I want to play a youtube video in a mediaplayer without the need of downloading the whole video (stream)
When you say media player, do you mean a video rendering control like WPF's media player?
yes, WPF mediaelement
You can probably just feed it the URL
Example using Vlc.DotNet.Core.
However I only play audio here.
I used RoslynPad to run this.
#r "$NuGet\AngleSharp\0.9.9\lib\net45\AngleSharp.dll"
#r "$NuGet\Newtonsoft.Json\10.0.3\lib\net45\Newtonsoft.Json.dll"
#r "$NuGet\YoutubeExplode\4.1.1\lib\net45\YoutubeExplode.dll"
#r "$NuGet\Vlc.DotNet.Core\2.2.1\lib\net45\Vlc.DotNet.Core.dll"
#r "$NuGet\Vlc.DotNet.Core.Interops\2.2.1\lib\net45\Vlc.DotNet.Core.Interops.dll"
using Vlc.DotNet.Core;
using Vlc.DotNet.Core.Interops.Signatures;
using YoutubeExplode;
using YoutubeExplode.Models.MediaStreams;
public const string VlcPath = @"C:\Program Files (x86)\VideoLAN\VLC";
var yt = new YoutubeClient();
var video = await yt.GetVideoMediaStreamInfosAsync("ETrhmFC_1TA");
var audio = video.Audio.WithHighestBitrate();
using(var client = new VlcMediaPlayer(new DirectoryInfo(VlcPath)))
{
client.SetMedia(new Uri(audio.Url));
client.Play();
while (client.State != MediaStates.Ended)
{
Thread.Sleep(1000);
}
}
Edit:
There are Wpf and WinForms controls for video in Vlc.DotNet.Wpf and Vlc.DotNet.Forms, they both have VlcControl to show video.
Of course this has it's downsides that machine has to have vlc installed and you have to choose x86 or x64 to use. Here is info for more details.
@SlowLogicBoy You can also use WithHighestBitrate extension method ;)
If you pass video to Client it opens new window and shows you the video:
#r "$NuGet\AngleSharp\0.9.9\lib\net45\AngleSharp.dll"
#r "$NuGet\Newtonsoft.Json\10.0.3\lib\net45\Newtonsoft.Json.dll"
#r "$NuGet\YoutubeExplode\4.1.1\lib\net45\YoutubeExplode.dll"
#r "$NuGet\Vlc.DotNet.Core\2.2.1\lib\net45\Vlc.DotNet.Core.dll"
#r "$NuGet\Vlc.DotNet.Core.Interops\2.2.1\lib\net45\Vlc.DotNet.Core.Interops.dll"
using Vlc.DotNet.Core;
using Vlc.DotNet.Core.Interops.Signatures;
using YoutubeExplode;
using YoutubeExplode.Models.MediaStreams;
public const string VlcPath = @"C:\Program Files (x86)\VideoLAN\VLC";
var yt = new YoutubeClient();
var video = await yt.GetVideoMediaStreamInfosAsync("ETrhmFC_1TA");
var muxed = video.Muxed.WithHighestVideoQuality();
using(var client = new VlcMediaPlayer(new DirectoryInfo(VlcPath)))
{
client.SetMedia(new Uri(muxed.Url));
client.Play();
while (client.State != MediaStates.Ended)
{
Thread.Sleep(1000);
}
}
@jvitoroc did your question get answered?
@SlowLogicBoy @Tyrrrz That's not what I'm looking for, maybe I'll stay with Electron.js.