private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { WMPLib.WMPPlayState state = (WMPLib.WMPPlayState)e.newState; Debug.WriteLine("Play state:" + state); switch (state) { case WMPLib.WMPPlayState.wmppsBuffering: break; case WMPLib.WMPPlayState.wmppsLast: break; case WMPLib.WMPPlayState.wmppsMediaEnded: break; case WMPLib.WMPPlayState.wmppsPaused: break; case WMPLib.WMPPlayState.wmppsPlaying: musicTimer.Start(); break; case WMPLib.WMPPlayState.wmppsReady: break; case WMPLib.WMPPlayState.wmppsReconnecting: break; case WMPLib.WMPPlayState.wmppsScanForward: break; case WMPLib.WMPPlayState.wmppsScanReverse: break; case WMPLib.WMPPlayState.wmppsStopped: var playId = m_curPlayId; m_curPlayId = 0; musicTimer.Stop(); tryPostPlayState(MusicPlayState.Stop, playId); //停止 break; case WMPLib.WMPPlayState.wmppsTransitioning: break; case WMPLib.WMPPlayState.wmppsUndefined: break; case WMPLib.WMPPlayState.wmppsWaiting: break; default: break; } }
private void axWindowsMediaPlayer1_PlayStateChange() { WMPLib.WMPPlayState cur_state = axWindowsMediaPlayer1.playState; if (cur_state == prev_state) return; else prev_state = cur_state; bool goon = false; string state; switch (cur_state) { case WMPLib.WMPPlayState.wmppsStopped: state = "Stopped"; goon = true; break; case WMPLib.WMPPlayState.wmppsPaused: state = "Paused"; break; case WMPLib.WMPPlayState.wmppsPlaying: state = "Playing"; break; case WMPLib.WMPPlayState.wmppsBuffering: state = "Buffering"; break; case WMPLib.WMPPlayState.wmppsTransitioning: state = "Transitioning"; break; case WMPLib.WMPPlayState.wmppsReady: state = "Ready"; goon = true; break; default: state = axWindowsMediaPlayer1.playState.ToString(); break; } string cur_media = axWindowsMediaPlayer1.currentMedia == null ? "null" : axWindowsMediaPlayer1.currentMedia.name; LogPlay("当前文件:\"" + cur_media + "\", 播放状态:" + state); if (goon && axWindowsMediaPlayer1.Dock == DockStyle.Fill && monitorON) { DoPlay(); } }
private void tmrPlayBack_Tick(object sender, System.EventArgs e) { // check if the state is changing if (LastPlayState != axWindowsMediaPlayer1.playState) { LastPlayState = axWindowsMediaPlayer1.playState; switch (axWindowsMediaPlayer1.playState) { case WMPLib.WMPPlayState.wmppsPlaying: btnFullScreenToggle.Enabled = true; DisableItemsDuringPlayback(); break; case WMPLib.WMPPlayState.wmppsStopped: case WMPLib.WMPPlayState.wmppsReady: EnableItemsWhenNotPlayingBack(); btnFullScreenToggle.Enabled = false; if (m_bCurrentPlayListWasLoaded) { lklDeletePlayList.Enabled = true; } break; } } // check the playstate of the Player if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying) { MovePlaybackTrackbar(); // check to see if it is playing the last playlist item for (int i = 0; i < axWindowsMediaPlayer1.currentPlaylist.count; i++) { if (axWindowsMediaPlayer1.currentMedia.get_isIdentical( axWindowsMediaPlayer1.currentPlaylist.get_Item( axWindowsMediaPlayer1.currentPlaylist.count - 1))) { // playing the last item // if it is playing the last playlist item OR it is only playing a single item // then check the duration against the current position double diff = axWindowsMediaPlayer1.currentMedia.duration - axWindowsMediaPlayer1.Ctlcontrols.currentPosition; if (diff < 0.5) { // if the duration is within .5 seconds of the current position, stop playing // and fire a STOPPED event StopPlayer(); } } } } else { } }
public wSoundPlayer() { player = new WMPLib.WindowsMediaPlayer(); state = player.playState; }