Reputation: 133
I'm trying to get an embedded YouTube video to play automatically when the page is loaded. I use this WPF code to set up my browser:
<wpf:ChromiumWebBrowser Address="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1"/>
The parameter ?autoplay=1
doesn't do the trick.
Upvotes: 0
Views: 1783
Reputation: 22089
The autoplay policy was changed by Google to give users more control over media playback.
If you do do not need sound, you can add the mute
parameter and set it to 1
, which will allow for autoplay.
<wpf:ChromiumWebBrowser Address="http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&mute=1"/>
If you need autoplay with sound you have to overwrite the autoplay-policy
in the settings. If you already have a settings initialization in your code, just add the following lines.
settings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required";
If you do not use settings, yet, add these lines to the constructor of your WPF application in App.xaml.cs
.
var settings = new CefSettings();
settings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required";
Cef.Initialize(settings, true, browserProcessHandler: null);
Upvotes: 2