Search code examples
c#wpfyoutube

Embedding Youtube videos in WPF application


I am trying to play a Youtube video right from my simple WPF application.

I have investigated several ways to do that:

  1. Using WebBrowser control In this case seems you just need to apply the Youtube video URL to WebBrowser source field and just make a little changes in the URL itself, like:

    Original URL = https://www.youtube.com/watch?v=xxxxxxx
    Changed URL = https://www.youtube.com/v/xxxxxxx

  2. The other approach just suggests to use ShockWave Flash object, which basically should have pretty the same result (video tutorial below)

https://www.youtube.com/watch?v=714w3HQDTcA

I have tried both cases and seems that the solutions are old, as I get the following error: enter image description here

So the question is:

Is there any way to simply play a youtube video in WPF app, with or without the described soultions. Or maybe I am doing something wrong. Thank you.


Solution

  • The cause of your problem

    When you're using the native WebBrowser control, remember that it's powered by Internet Explorer (not sure if Windows 10 uses Edge to handle that control), both outdated browsers that likely don't support the new YouTube player. YouTube switched its video player in favor of the new HTML5 one and flash stopped being supported thus, the ShockWave Flash Object not working.

    A possible solution

    What you can try to do is using a more modern embedded browser. In C#, your best option might be a CEF port to C#, CefSharp. CEF stands for Chromium Embedded Framework and, because Chromium is the base for Google Chrome, just keep the library updated and you'll always have support for the newest features in Web browsers.