![](/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.