I'm adding VLC support for my VoiceAttck (voice recognition) plugin for a flight sim.
I instantiated a Media object and start playing.
The object is stored globally in Globals.vaProxy.SessionState so the user can stop/pause/next etc.
What I am trying to achieve is a continues play.
I cannot wait for teh song to end - this will not enable me to run other commands, therefore I tried to add an event:
Code: Select all
mediaPlayer.EndReached += MediaPlayer_MediaEnded;
mediaPlayer.Play(media);
private static void MediaPlayer_MediaEnded(object sender, EventArgs e)
{
PlayNextSong();
}
private static void PlayNextSong()
{
MediaPlayer mediaPlayer = Globals.vaProxy.SessionState["player"];
List<Media> playList = Globals.vaProxy.SessionState["playList"];
if (playList.Count > 0)
{
var nextMedia = playList[0];
playList.RemoveAt(0);
var state = mediaPlayer.State;//I get to this in the debugger and the stated is "Ended"
mediaPlayer.Play(nextMedia);//I step through here but no song is played
}
else
{
Console.WriteLine("Playlist ended.");
// Perform any necessary actions when the playlist ends
// Stop the media player and clean up resources
mediaPlayer.Stop();
mediaPlayer.Dispose();
Globals.vaProxy.SessionState["player"] = null;
Globals.vaProxy.SessionState["playList"] = null;
}
}
Code: Select all
var state = mediaPlayer.State;//I get to this in the debugger and the stated is "Ended"
mediaPlayer.Play(nextMedia);//I step through here but no song is played
Thanks