我有一个列表框,其中包含所有必须播放的媒体文件。如何让媒体播放器一一播放?此代码播放 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;
> }