本文介绍了用axWindwosMediaPlayer C#恢复歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用C#制作的媒体播放器遇到了一些问题,我认为这将是最后一个问题..



我有两个按钮:播放和暂停。单击播放时,正在播放列表框中的选定歌曲。如果我单击暂停,则歌曲会正确暂停。但如果我再次点击播放按钮继续播放歌曲,它会重新播放我正在播放的歌曲。



我正在使用:

I'm having some problems with a media player that I'm making in C#, I think this will be the last problem..

I have two buttons: Play and Pause. When I click Play, a selected song from a listbox is being played. If I click Pause, the song pauses correctly. But if I click on Play button again to resume the song, it restarts the song I was playing.

I'm using:

private void button3_Click(object sender, EventArgs e) //Play Button
       {
          axWindowsMediaPlayer1.URL = mediaList[listBox1.SelectedIndex];
          if(axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)
               {
                  axWindowsMediaPlayer1.Ctlcontrols.play();
               }else
               {
                  axWindowsMediaPlayer1.Ctlcontrols.pause();
               }
       }





mediaList 是一个列表用于保存listBox1上的播放列表。



先谢谢。



mediaList is a list for saving the playlist on listBox1.

Thanks in Advance.

推荐答案

//code 1
if(!string.IsNullOrEmpty(axWindowsMediaPlayer1.URL)
{
   // URL set, you can pause or play current video 
   // check below Code2
}else
{
   // need to set the url from your mediaList selected item and play the video from beginning 
}



如果您已经设置了网址,那么您的视频可能会被暂停,那么您需要播放它,否则您需要暂停它


if you already have URL set then your video may be paused then you need to play it otherwise you need to paused it

//code2
if(axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused){
    // video paused, resume it  
    axWindowsMediaPlayer1.Ctlcontrols.play();
}else{
    // otherwise pause the video
    axWindowsMediaPlayer1.Ctlcontrols.pause();
}



完整代码:


full code:

private void button3_Click(object sender, EventArgs e)
       {
          if(!string.IsNullOrEmpty(axWindowsMediaPlayer1.URL)
          {
             if(axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused){
                axWindowsMediaPlayer1.Ctlcontrols.play();
             }else{
               axWindowsMediaPlayer1.Ctlcontrols.pause();
             }
          }else
          {
             axWindowsMediaPlayer1.URL = mediaList[listBox1.SelectedIndex];
             axWindowsMediaPlayer1.Ctlcontrols.play();
          }

       }


这篇关于用axWindwosMediaPlayer C#恢复歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:59