1

我有一个列表框,其中包含所有必须播放的媒体文件。如何让媒体播放器一一播放?此代码播放 1 首歌曲,但 foreach 应该播放所有文件,但我怀疑这是因为它不会等到媒体结束.. 这段代码:

Listbox = listBox3

listBox3Dict[s]= 列表框中所有文件的字符串

            Dictionary<string, string> listBox3Dict = new Dictionary<string, string>();

>         private bool listbox3job()
>         {
>             AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
>                 {
>                     foreach (var selected in listBox3.Items)
>                     {
>                         string s = selected.ToString();
> 
>                         if (listBox3Dict.ContainsKey(s))
>                         {
WMPLib.IWMPPlaylist playlist = axWindowsMediaPlayer1.newPlaylist("myPlaylist", string.Empty);
                            // you can add songs to url on for loop 
                            WMPLib.IWMPMedia temp = this.axWindowsMediaPlayer1.newMedia(listBox3Dict[s]); //Load media from URL. 
                            playlist.appendItem(temp); //Add song to playlist.
                            // after you add all songs set the new playlist
                            this.axWindowsMediaPlayer1.settings.autoStart = true; //not necessary
                            this.axWindowsMediaPlayer1.currentPlaylist = playlist; //Set media player to use the playlist.
>                         }
>                     }
> 
>                 return true;
>             }
>             return false;
>         }
4

2 回答 2

3

您可以做的是创建播放器列表并开始播放该列表

private bool listbox3job()
{

    AxWMPLib.AxWindowsMediaPlayer axWmp = wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
    WMPLib.IWMPPlaylist playlist = axWmp.newPlaylist("myPlaylist", string.Empty);

    foreach (var selected in listBox1.Items)
    {
        string s = selected.ToString();
        if (listBox3Dict.ContainsKey(s))
        {
            WMPLib.IWMPMedia temp = axWmp.newMedia(listBox3Dict[s]); //Load media from URL. 
            playlist.appendItem(temp); //Add song to playlist.
        }
    }
    axWmp.settings.autoStart = true; //not necessary
    axWmp.currentPlaylist = playlist; //Set media player to use the playlist.
    return true;
}

http://www.timwylie.com/playlist.html

于 2013-04-19T07:56:56.843 回答
0

早些时候,我正在处理列表中的一组语音文件。我使用了 PlayStateChange 事件。从此事件中,您可以找到 MediaEnded 状态,您可以在其中将播放文件重新分配给列表中的下一项。

于 2013-04-19T08:50:37.457 回答