如何更改WebBrowser全屏视频模式? [英] How to change WebBrowser fullscreen video mode?

查看:43
本文介绍了如何更改WebBrowser全屏视频模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 TableLayoutPanel 中有一个带有2个 WeBBrowser 的c ++项目,它们并排设置,工作正常,但我可以正常浏览,但是当我转到特定网站并玩游戏时全屏播放的视频将我的整个显示器设置为全屏显示,而不是仅设置 WeBBrowser 本身,但是在其他网站上,该视频非常适合 WeBBrowser .有没有办法改变全屏显示的方式?我想让它仅在 WeB browser 中全屏显示.我认为这与 WebBrowserBase.ActiveXInstance 属性或 WebBrowser.Document 属性有关.我在互联网上找到的大多数示例都是针对旧VB的,与全屏属性无关.

I have a c++ project with 2 WeBBrowser in a TableLayoutPanel they are set side by side, it's working fine I navigate normal but when I go to specific websites and play a video in fullscreen that sets my whole monitor to fullscreen instead of setting only the WeBBrowser itself, however on other websites that fits perfect in the WeBBrowser. Is there a way to change the way it displays fullscreen? I wanna make it display fullscreen in the WeB​Browser only. I think it has something to do with Web​Browser​Base.​Active​XInstance Property or Web​Browser.​Document Property. Most examples I find on the internet is for the old VB and not related to the fullscreen property.

这是一个类似的问题: WebBrowser控件视频元素进入全屏

Here's a similar question: WebBrowser control video element enter fullscreen

在其他示例中,我看到了一种通过执行以下操作提取元素的方法:

In other examples I've seen a method to extract the element by doing:

HtmlElement^  object = webBrowser1->Document->GetElementById("video");

但是我不知道如何处理该代码以格式化该视频,然后将其设置回固定为全屏模式的 WeBBrowser .

But I have no idea how to handle that code in order to format that video then set it back to the WeBBrowser with fullscreen mode fixed.

我走得更远,我可以从几个网站上获取< video> 元素,这是我的方法:

I went further and I could get the <video> element just from a few websites, here's my method:

private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) {
        HtmlElementCollection^  videoElements = webBrowser1->Document->GetElementsByTagName("video");
        videoElements[0]->SetAttribute("style", "width: 640px; height: 480px;"); //Not sure if this is a proper way to set an attribute in this element.
    }

问题在于,并非每个网站都允许您访问< video> 标记元素,因此对于这些网站,我执行了以下代码以确保确实没有< video> 标记源中的元素:

The problem is that not every website gives you access to <video> tag elements, so for those websites I did the following code to make sure there were indeed no <video> tag elements in the source:

System::Diagnostics::Debug::Write(webBrowser1->DocumentText);

然后,我在输出中没有找到任何< video> 标记元素,只有少数网站为我提供了该标记元素.为什么?如何在C ++中真正获取并正确地操作< video> 标记元素?

Then I didn't find any <video> tag element in the output, only a few websites provide me that. Why? How to really get and manipulate properly <video> tag elements in c++?

推荐答案

然后我在输出中没有找到任何标签元素,只有少数网站为我提供了该元素.为什么?

Then I didn't find any tag element in the output, only a few websites provide me that. Why?

让我做出有根据的猜测.对于您要参考的某些页面,DOM是动态和异步构建的.这意味着,这些< video> 标签可能根本就不存在.

Let me make an educated guess. For some of the pages you're referring to, the DOM is built dynamically and asynchronously. Which means, those <video> tags might simply not be there yet.

因此,您可能需要适当的异步轮询逻辑来监视DOM的变化,特别是寻找< video> 标记.

So, you might need to have some asynchronous polling logic in place that monitors DOM changes, specifically looking for <video> tags.

可能无法提出涵盖所有情况的100%有效解决方案,但请参阅我的其他帖子处理此问题.

It might not be possible to come up with a 100% working solution to cover all cases, but have a look at my other post which deals with this problem.

这篇关于如何更改WebBrowser全屏视频模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆