我有一个列表框,其中包含所有必须播放的媒体文件。如何让媒体播放器逐一播放? 这段代码播放了一首歌但是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;
> }
答案 0 :(得分: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;
}
答案 1 :(得分:0)
之前我在列表中处理一组语音文件。我使用了PlayStateChange事件。通过此事件,您可以找到MediaEnded状态,您可以在其中将播放文件重新分配给列表中的下一个项目。