![](/img/trans.png)
[英]How to use System.Media.SoundPlayer to asynchronously play a sound file?
[英]Do … While System.Media.SoundPlayer() is in use
我一直在尝试在播放声音文件的同时在控制台应用程序上显示文本,例如歌词。 最好的方法是什么?
struct Music
{
public
void PlaySong() {
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"C:\Users\MyPC\Music\MoreMusic\songsample.wav";
player.Load();
player.PlaySync();
}
}
class Program
{
static public void Main(string[] args)
{
Music music;
do
{
//Display Lyrics
} while (true); //as the song progresses
}
}
将PlaySync替换为Play
struct Music
{
public
void PlaySong() {
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"C:\Users\MyPC\Music\MoreMusic\songsample.wav";
player.Load();
player.Play();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.