I do not see anything in your code which sets a value to the _currentSong. Probably, it is coming as null and your code is not getting executed.
if (_songList.Count > 0 && _currentSong != null)
Frage
I have a problem with looping a list of songs. I have a List<String> _songList
which contains songs paths (loaded correctly, checked). So I thought that there is an event which will tell me "Ok I stopped playing the song, I'm ready to play the next one". In NAudio
it should be StoppedEventArgs
added to WaveOutEvent.PlaybackStopped
. But in my case it doesn't play another song, neither the same again. Here is my code:
public void Play_List(String _playlistName)
{
try
{
if (_songList.Count > 0)
{
if (!_paused)
{
_currentList = _playlistName;
PrimaryOutputStream =
new MediaFoundationReader(_songList[_songIndex]);
VolumeStream = new WaveChannel32(PrimaryOutputStream);
VolumeStream.PadWithZeroes = false;
Player.Init(VolumeStream);
Player.PlaybackStopped +=
new EventHandler<StoppedEventArgs>(RepeatMode);
}
Player.Play();
_paused = false;
_isPlaying = true;
}
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.ToString());
}
}
public void RepeatMode(object sender, StoppedEventArgs e)
{
try
{
if (_songList.Count > 0 && _currentSong != null)
{
_paused = false;
switch (_repeatMode)
{
case 1: //Repeat one song
Play_List(_currentList);
break;
case 2: //Repeat whole list
NextSong();
Play_List(_currentList);
MessageBox.Show("Changed song");
break;
default:
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Of course I set _repeatMode to 2 for list and 1 for one song. I was searching the internet for help but found nothing. Anyone?
Lösung
I do not see anything in your code which sets a value to the _currentSong. Probably, it is coming as null and your code is not getting executed.
if (_songList.Count > 0 && _currentSong != null)