Page 1 of 1

LibVLCSharp not playing youtube videos

Posted: 03 Nov 2020 14:15
by karnati8
I cannot get a youtube video to play with LibVLCSharp. I followed the documented example but it still doesn't work. I have a checkbox on my form (chkYouTube) with which I indicate that the url is a youtube url.
Any other links work fine (which uses the else part of the if statement below).

At one stage I could get it going outside of my control, but even that I could not do again.
_mp.Play() returns true but MediaPlayer.IsPlaying is false

videoView2 just shows blank. No errors.

private async void btnGo_Click(object sender, EventArgs e)
{

if (chkYouTube.Checked)
{
using (LibVLC _libVLC = new LibVLC("--preferred-resolution=240"))
{
Media media = new Media(_libVLC, txtURL.Text.Trim(), FromType.FromLocation);
await media.Parse(MediaParseOptions.ParseNetwork);

using (MediaPlayer _mp = new MediaPlayer(media.SubItems.First()))
{
videoView2.MediaPlayer = _mp;
videoView2.Visible = true;
videoView2.BringToFront();
var r = _mp.Play();
}
}


}
else
{
LibVLC _libVLC = new LibVLC("--preferred-resolution=240");

Media media = new Media(_libVLC, txtURL.Text.Trim(), FromType.FromLocation);

MediaPlayer _mp = new MediaPlayer(_libVLC);

_mp.EncounteredError += _mp_EncounteredError;
videoView2.MediaPlayer = _mp;
videoView2.Visible = true;
videoView2.BringToFront();
_mp.Play(media);
}

}

Re: LibVLCSharp not playing youtube videos

Posted: 04 Nov 2020 03:46
by mfkl
Hi,

Please share your full code in a git repo (and especially the Youtube URL used).

Re: LibVLCSharp not playing youtube videos

Posted: 04 Nov 2020 08:05
by karnati8
Here is the full test project.

https://github.com/karnati8/Research

Re: LibVLCSharp not playing youtube videos

Posted: 04 Nov 2020 10:53
by mfkl
and especially the Youtube URL used

Re: LibVLCSharp not playing youtube videos

Posted: 04 Nov 2020 18:32
by karnati8
The url is in the code that I've shared.
Here it is anyway:
https://www.youtube.com/watch?v=dQw4w9WgXcQ

Re: LibVLCSharp not playing youtube videos

Posted: 09 Nov 2020 04:11
by mfkl
The url is in the code that I've shared.
Sorry, couldn't find it.

Code: Select all

http error: local stream 1 error: Cancellation (0x8) http error: local stream 1 error: Stream closed (0x5) lua error: Couldn't extract youtube video URL, please check for updates to this script
VLC 3.0.11 cannot play it. You can either update the lua script in your installation (replace your version with https://github.com/videolan/vlc-3.0/blo ... outube.lua) or wait for 3.0.12 which should fix this.

Re: LibVLCSharp not playing youtube videos

Posted: 09 Nov 2020 08:35
by karnati8
Thanks mfkl,
I have replaced the lua with this version before but it does not make a difference in my test app.

Just to be clear, although all youtube videos play very well inside VLC on my machine, NO youtube videos plays in my test app that I've shared above. It is not specific to this url. I can choose any youtube url, it won't play in my test app.

Have you had a chance to run my test app on your machine and run it with any youtube url? Can you see the problem?

Re: LibVLCSharp not playing youtube videos

Posted: 10 Nov 2020 04:52
by mfkl
Have you had a chance to run my test app on your machine and run it with any youtube url? Can you see the problem?
No, it doesn't build. Its missing files, try a clean clone and restore.

Code: Select all

error MSB3552: Resource file "Properties\Resources.resx" cannot be found.

Re: LibVLCSharp not playing youtube videos

Posted: 10 Nov 2020 08:51
by karnati8
Ah, I forgot the Properties folder. Added it. Please try again.

Re: LibVLCSharp not playing youtube videos

Posted: 10 Nov 2020 10:05
by mfkl
don't dispose of the mediaplayer or libvlc objects, it stops everything.

do enable verbose logs, otherwise you can't begin to troubleshoot the problem.

do use another youtube URL, OR update the lua script.

https://github.com/karnati8/Research/pull/1

Re: LibVLCSharp not playing youtube videos

Posted: 10 Nov 2020 13:05
by karnati8
Thank you mfkl! It works now. I've blindly used the documented example without thinking that the using would dispose the mediaplayer before it started to play the video.
Much appreciated.

Re: LibVLCSharp not playing youtube videos

Posted: 11 Nov 2020 06:45
by JHustermeier
I found a good Video explaining this for Windows: https://www.youtube.com/watch?v=dao90mUeeEI

My Problem: want to make it work on MAC OS,
can anyone tell me how to update the LUA Script on MAC OS?

A step by step would be really helpfull, for I think I could not manage it without.

Thanks a Lot in advance.