Unable to continually play songs using LibVLCSharp
Posted: 23 May 2023 22:13
Hi,
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:
The problem is that no song is played and no error appears when I reach teh code which is supposed to Play() the song in the triggred function: this one:
What is wrong, or how CAN I achieve continues play without waiting for a song to end but with the ability to still control the object externally?
Thanks
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