-
Notifications
You must be signed in to change notification settings - Fork 7
Add support for Widevine CDM csharp ( C# & C )
Cef.RegisterWidevineCdm(@"WidevineCdm");
Cef.RegisterWidevineCdmAsync(@"WidevineCdm");
settings.CefCommandLineArgs.Add("enable-widevine", "1");
settings.CefCommandLineArgs.Add("enable-widevine-cdm", "1");
Widevine in a DRM system developed by Google and used by companies like YouTube and Netflix to protect HTML5 video. The binary component used by Chromium, called the Widevine CDM, is a Pepper plugin that is downloaded on Windows and OS X via the Chrome component updater [1] (download on Linux is not yet supported, see WIDEVINE_CDM_IS_COMPONENT usage). Automated download of the binary from Google is allowed but bundling of the Widevine CDM with third-party applications requires a license.
To add support for Widevine CDM in CEF the following changes will be required:
Add a dependency on /third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h and /components/components.gyp:cdm_renderer (cdm_browser is Android-only currently). Download the binaries [2] from Google, possibly using the component updater (see chrome/browser/component_updater/widevine_cdm_component_installer.cc, RegisterComponentsForUpdate in chrome/browser/chrome_browser_main.cc). Register the Pepper plugin. Implement ContentRendererClient::AddKeySystems (see AddChromeKeySystems in chrome/renderer/media/chrome_key_systems.cc). Additional logic related to content settings may also be required (see ShouldUseJavaScriptSettingForPlugin usage in chrome/renderer/chrome_content_renderer_client.cc and chrome/browser/plugins/plugin_info_message_filter.cc). Related variables include:
enable_pepper_cdms (GYP, on by default in common.gypi) WIDEVINE_CDM_AVAILABLE (defined in third_party/widevine/cdm/stub/widevine_cdm_version.h) WIDEVINE_CDM_IS_COMPONENT (defined in third_party/widevine/cdm/widevine_cdm_common.h, currently Windows and OS X only) [1] https://chromium.googlesource.com/chromium/chromium/+/trunk/chrome/browser/component_updater
[2] libwidevinecdm.dylib, widevinecdm.dll, libwidevinecdm.so, widevinecdmadapter.plugin, widevinecdmadapter.dll, libwidevinecdmadapter.so
-
Build CEF/Chromium with support for proprietary codecs. set GYP_DEFINES=proprietary_codecs=1 ffmpeg_branding=Chrome
-
Run cefclient with CDM support and cache path.
Windows:
cefclient.exe --enable-widevine-cdm --cache-path=c:\temp\cache
OS X:
open cefclient.app --args --enable-widevine-cdm --cache-path=/Users/marshall/temp/cache
Linux:
cefclient --widevine-cdm-path=/opt/google/stable --widevine-cdm-version=1.4.8.824 --cache-path=/home/marshall/temp/cache
public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
var headers = request.Headers;
headers["Custom-Header"] = "My Custom Header";
request.Headers = headers;
return CefReturnValue.Continue;
}
Anyone got an answer for my question above re loading a page into the control when the WPF TabItem it is on it doesn't have focus?
@nzmike99 The default WPF TabControl
isn't really suitable for hosting a browser, see
When I add the ChromiumWebBrowserWithScreenshotSupport.cs file to the CefSharp.Wpf.Example project it needs the "using GalaSoft.MvvmLight.Command; " dependency which destroys the project with errors
@jeremiahjordani_twitter You could use any Delegate/RelayCommand implementation you like. Pretty common for WPF apps to have one.
If you don't have one then just change the access modifier for the paramaterless TakeScreenshot so it's usable in your instance. The command is entirely optional.
private void /*Btn*/Sceenshot_Click(object sender, RoutedEventArgs e)
{
/*
//CefSharp - Quick and Dirty Screenshot with no class dependency
MessageBox.Show("Take screenshot");
double dWidth = (webCefSharpChromiumWebBrowser.ActualWidth);
double dHeight = (webCefSharpChromiumWebBrowser.ActualHeight);
int actualWidth = 0;
int actualHeight = 0;
actualWidth = Convert.ToInt32(dWidth);
actualHeight = Convert.ToInt32(dHeight);
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(actualWidth, actualHeight, 90, 90, PixelFormats.Pbgra32);
renderTargetBitmap.Render(webCefSharpChromiumWebBrowser);
PngBitmapEncoder pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
using (Stream fileStream = File.Create(@"C:\SaveFolderName\apollo.png")) //uses System.IO for fileStream
{
pngImage.Save(fileStream);
}
*/
}
[C#
] TakeScreenshot [WPF
]
/*Here is an example that reuses the image that's already rendered to the screen.*/
var template = Browser.Template;
var image = (System.Windows.Controls.Image)template.FindName("PART_image", Browser);
var pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create((System.Windows.Media.Imaging.BitmapSource)image.Source));
var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot" + DateTime.Now.Ticks + ".png");
using (var fileStream = File.Create(screenshotPath))
{
pngImage.Save(fileStream);
}