C# - 如何在完成后播放音频文件? [英] C# - How to play an audio file after another finishes ?
本文介绍了C# - 如何在完成后播放音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我想从文件夹中播放多个音频文件,但我只播放第一个文件
这个是我的代码:
Hi all!!
I want to play multiple audio file from a folder, but I only play the first file
This is my code :
List<string> wavlist = new List<string>();
wavlist.Add(Application.StartupPath + "\\mp3\\1.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\2.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\3.mp3");
wavlist.Add(Application.StartupPath + "\\mp3\\4.mp3");
foreach (string file in wavlist)
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = file;
wplayer.control.play();
}
请帮帮我!
@ _ @
谢谢和最好的问候。
Please help me!
@_@
Thanks and best regards.
推荐答案
您可以创建一个播放列表并使用它来顺序播放文件。以下是示例代码:
You can create a playlist and use that to play files sequentially. Here is sample code to do so:
WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("NewPlaylist");
// Add files to playlist. You can make use of a loop to add multiple files
WMPLib.IWMPMedia fileMedia = player.newMedia(filePath);
playlist.appendItem(fileMedia);
player.currentPlaylist = playlist;
player.Ctlcontrols.play();
另一种方法是使用 PlayStateChanged
事件处理程序。
这篇关于C# - 如何在完成后播放音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文