我在 Microsoft Edge (Chromium) 上安装了 Chrome 扩展程序来播放 HLS 视频。我已经尝试过 Microsoft Edge (Chromium),它运行良好。HLS URL 为http://localhost/hls/taiguo/playlist.m3u8,在 Microsoft Edge 浏览器上显示 URL 如下:extension://ekcifneimckhkjdfklkkpdlnckcjhmke/index.html# http://localhost/hls/taiguo/播放列表.m3u8。
当我使用 WebView2 将浏览器嵌入到 Windows 应用程序中时,遵循 [WebView2 入门(开发者预览版)](https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/gettingstarted)示例代码:
` CreateCoreWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, Callback( [hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
RETURN_IF_FAILED(result);
// Create a CoreWebView2Host and get the associated CoreWebView2 whose parent is the main window hWnd
env->CreateCoreWebView2Host(hWnd, Callback<ICoreWebView2CreateCoreWebView2HostCompletedHandler>(
[hWnd](HRESULT result, ICoreWebView2Host* host) -> HRESULT {
if (host != nullptr) {
webviewHost = host;
webviewHost->get_CoreWebView2(&webviewWindow);
}
// Add a few settings for the webview
// this is a redundant demo step as they are the default settings values
ICoreWebView2Settings* Settings;
webviewWindow->get_Settings(&Settings);
Settings->put_IsScriptEnabled(TRUE);
Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
Settings->put_IsWebMessageEnabled(TRUE);
// Resize WebView to fit the bounds of the parent window
RECT bounds;
GetClientRect(hWnd, &bounds);
webviewHost->put_Bounds(bounds);
// Schedule an async task to navigate to Bing
webviewWindow->Navigate(L"http://localhost/hls/taiguo/playlist.m3u8");`
如果我运行上面的代码,应用程序只会下载 playlist.m3u8 文件而不播放视频。如果我将 webviewWindow->Navigate(...) 的 URL 参数更改为:
webviewWindow->Navigate(L"extension://ekcifneimckhkjdfklkkpdlnckcjhmke/index.html#http://localhost/hls/taiguo/playlist.m3u8");
然后我收到如下所示的错误消息: App screen capture
我希望有人能告诉我如何使用 WebView2 API 运行扩展。