我正在尝试编写一个支持 webrtc 的 wpf。对相机的访问有效,但<video>
来自页面的显示无效。任何人都可以帮忙吗?
3 回答
You can do something like this:
var cefSettings = new CefSettings();
cefSettings.CefCommandLineArgs.Add("enable-media-stream", "enable-media-stream");
Cef.Initialize(cefSettings);
This has the same effect as passing the command line argument
我假设您想通过 WebRTC 从您的相机显示视频,所以我认为它需要一个电话来.getUserMedia()
获取您的相机。为此,您必须使用基于 Chromium 30 或更高版本的 CefSharp。所以要么:
- 使用最新的 CefSharp.Wpf NuGet。现在你需要最新
-Pre
版本 - 或使用当前
master
分支从源代码构建。
我刚刚使用CefSharp.MinimalExample再次进行了快速测试,因此步骤如下:
确保您的 MinimalExample 使用 Chromium 31 或更高版本 - 请参阅此 PR - 除非在您阅读本文时它已经合并。
在将属性
MainView.xaml
修改为“ https://simpl.info/getusermedia/sources/index.html ”<cefSharp:WebView Address= />
构建并在运行时添加
--enable-media-stream
命令行标志。
而已!连接好相机并且运气好的话,您应该可以在屏幕上看到自己的脸——或者相机指向的任何东西。
奖励信息:希望 PR #365 很快就能获得一些额外的爱,以允许传递标志并合并到 CefSharp。有了它,您可以在代码中设置标志,而不必将其作为命令行参数传递。
正确的代码是这个
Dim settings As New CefSettings settings.CefCommandLineArgs.Add("--enable-media-stream", "1") CefSharp.Cef.Initialize(settings) settings.CachePath = "cache"