wpf 媒体播放器如何播放列表框中的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16099821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Media player play all files in listbox how?
提问by Sneakybastardd
I have a listbox that contains all media files that has to be played. How do make media player play 1 by one? This code plays 1 song but foreach is supposed to play all files, but I quess that is because it doesn't wait till media ended.. this code:
我有一个列表框,其中包含必须播放的所有媒体文件。如何让媒体播放器1个播放?此代码播放 1 首歌曲,但 foreach 应该播放所有文件,但我怀疑这是因为它不会等到媒体结束.. 这段代码:
Listbox = listBox3
Listbox = listBox3
listBox3Dict[s]= string for all files in listbox
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;
> }
回答by Damith
what you can do is create player list and start play that list
您可以做的是创建播放器列表并开始播放该列表
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;
}
回答by KbManu
Earlier I was working on a set of speech files in a list. I used PlayStateChange event. From this event you can find MediaEnded state where you can reassign the playfile to next item in the list.
早些时候,我正在处理列表中的一组语音文件。我使用了 PlayStateChange 事件。在此事件中,您可以找到 MediaEnded 状态,您可以在其中将播放文件重新分配给列表中的下一项。

