[英]How to play a List of songs using naudio and c#?
I have a problem when I try to play a list of songs, my code does not work. 尝试播放歌曲列表时出现问题,我的代码不起作用。 Only the first few seconds each song plays but I want to play all the contents of each song list:
每首歌曲仅播放前几秒钟,但我想播放每首歌曲列表的所有内容:
private void Play()
{
List<Song> songList = ViewModelLocator.Instance.SongListVM.Songs;
foreach(Song song in songList)
{
audioFileReader = new AudioFileReader(song.Path);
waveOutDevice.Init(audioFileReader);
waveOutDevice.Play();
}
}
I tried to use a Thread: 我试图使用一个线程:
waveOutDevice.Play();
Thread.Sleep(audioFileReader.TotalTime);
but it only hangs. 但它只是挂起。
For me I used this : 对我来说,我使用了这个:
int song_index=0; // index of the song
private void player_play()
{
outputdevice.PlaybackStopped += playbackstopped;
if (outputdevice.PlaybackState != PlaybackState.Paused)
{
to_play = playlist.Rows[song_index].Cells[0].Value.ToString();
audiofile = new AudioFileReader(to_play);
outputdevice.Init(audiofile);
}
outputdevice.Play();
}
// this event occur when the playing file has ended
private void playbackstopped(object sender, StoppedEventArgs e)
{
song_index++; // play the next file
player_play();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.