How to change WebBrowser fullscreen video mode?

我与影子孤独终老i 提交于 2019-12-08 08:57:42

问题


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.

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");

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.

EDIT:

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.
    }

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);

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++?


回答1:


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

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.

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

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.



来源:https://stackoverflow.com/questions/55622038/how-to-change-webbrowser-fullscreen-video-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!