当我尝试播放歌曲列表时遇到问题,我的代码无效。每首歌只播放前几秒,但我想播放每首歌曲列表的所有内容:
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();
}
}
我尝试使用线程:
waveOutDevice.Play();
Thread.Sleep(audioFileReader.TotalTime);
但它只挂起。
答案 0 :(得分:0)
对我来说,我用过这个:
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();
}