Unable to continually play songs using LibVLCSharp

This forum is about all development around libVLC.
fanfan21
New Cone
New Cone
Posts: 7
Joined: 23 May 2023 21:59

Unable to continually play songs using LibVLCSharp

Postby fanfan21 » 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:

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; } }
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:

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
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

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Unable to continually play songs using LibVLCSharp

Postby mfkl » 24 May 2023 07:05

Please share full verbose libvlc logs and a small standalone sample on github reproducing the issue.
https://mfkl.github.io

fanfan21
New Cone
New Cone
Posts: 7
Joined: 23 May 2023 21:59

Re: Unable to continually play songs using LibVLCSharp

Postby fanfan21 » 24 May 2023 14:42

Please share full verbose libvlc logs and a small standalone sample on github reproducing the issue.
Hi,
there is no long or I do not know ow to enable a full log for these objects:

Code: Select all

var libVlc = new LibVLC(); var playList = new Media(libVlc, playListFile);
How do I enble the logging?

I created a simple example here:
https://github.com/karpiyon/VLC_Debug
You need to define, the Program.cs

Code: Select all

var musicDirectory = @"Any folder containing several music files";
What I am trying to achieve there is the trigger the "EndReached" event in VlcPlayer.cs.
I also want to make sure that if you do manage to make the event work and play the next song, it will be able to keep playing the next song after that and all the rest.
I can still control the MediaPlayer object externally.

Thanks.

fanfan21
New Cone
New Cone
Posts: 7
Joined: 23 May 2023 21:59

Re: Unable to continually play songs using LibVLCSharp

Postby fanfan21 » 24 May 2023 15:54

I enabled debugging using
var libVlc = new LibVLC(enableDebugLogs:true);
and I see this right after the media ends:

[000001e3c11ae170] main input debug: Buffering 99%
[000001e3c11ae170] main input debug: Stream buffering done (1018 ms in 203 ms)
[000001e3c11ae170] main input debug: Decoder wait done in 0 ms
[000001e3c150acd0] main audio output warning: playback too early (-62248): down-sampling
[000001e3c150acd0] mmdevice audio output debug: state changed: 1
[000001e3c13f1dd0] mpegaudio demux packetizer debug: emulated startcode (no startcode on following frame)
[000001e3c11ae170] main input debug: EOF reached
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty
[000001e3c11ae170] main input debug: waiting decoder fifos to empty

Then, once the fifo it is empty I reach this in the debugger:
mediaPlayer.Play(nextMedia);
and nothing happens and no more log lines are written.

fanfan21
New Cone
New Cone
Posts: 7
Joined: 23 May 2023 21:59

Re: Unable to continually play songs using LibVLCSharp

Postby fanfan21 » 25 May 2023 18:29

Please share full verbose libvlc logs and a small standalone sample on github reproducing the issue.
Did you have a chnage to look at it?

It requires these nuget:
LibVLCSharp & VideoLAN.LibVLC.Windows

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Unable to continually play songs using LibVLCSharp

Postby mfkl » 26 May 2023 07:57

Code: Select all

Task.Run(() => mediaPlayer.Play(nextMedia));
Try this. And remove all your thread.sleep from your code, this is terrible practice.
https://mfkl.github.io

fanfan21
New Cone
New Cone
Posts: 7
Joined: 23 May 2023 21:59

Re: Unable to continually play songs using LibVLCSharp

Postby fanfan21 » 26 May 2023 12:04

Code: Select all

Task.Run(() => mediaPlayer.Play(nextMedia));
Try this. And remove all your thread.sleep from your code, this is terrible practice.
I added teh steep() because without this delay it fails to play the songs most of the time.
how then can i assure the player is ready to play?


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 2 guests