private void MediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { if (e.newState == 8)//MediaEnded { localTrackState = LocalTrackState.End; } }
private void PlayLocalTrack() { if (tracks.Length > 0) { var t = tracks[random.Next(tracks.Length)]; mediaPlayer.URL = t; mediaPlayer.Ctlcontrols.play(); localTrackState = LocalTrackState.Play; } else { localTrackState = LocalTrackState.End; } }
/** * Contains the logic for when to mute Spotify **/ private void MainTimer_Tick(object sender, EventArgs e) { var s = hook.Check(); if (s != SpotifyState.NonHooked) { if (MainTimer.Interval != 200) { MainTimer.Interval = 200; } if (s == SpotifyState.PlayingAd && localTrackState == LocalTrackState.Stop) { if (!hook.IsMuted) { hook.Mute(true); } PlayLocalTrack(); if (!hook.IsPlaying()) //if Spotify is not playing Ad, play next { hook.NextTrack(); Thread.Sleep(500); } } else if (s == SpotifyState.Playing && localTrackState == LocalTrackState.Play) // end of ad, pause spotify while local trac end { hook.PlayPause(); } else if (s == SpotifyState.Pause && localTrackState == LocalTrackState.End) // local track end, resume spotify { hook.PlayPause(); localTrackState = LocalTrackState.Stop; } else if (s == SpotifyState.Playing) // Normal music { if (hook.IsMuted) { Thread.Sleep(500); // Give extra time for ad to change out hook.Mute(false); } StatusLabel.Text = Properties.strings.StatusPlaying; } else if (s == SpotifyState.Pause) // Normal music { StatusLabel.Text = Properties.strings.StatusPaused; } else { StatusLabel.Text = Properties.strings.StatusUnknown; } } else { if (MainTimer.Interval != 1000) { MainTimer.Interval = 1000; } StatusLabel.Text = Properties.strings.StatusNotFound; } }