How to disable sound on flashplayer in my custom application?

给你一囗甜甜゛ 提交于 2020-01-01 14:24:36

问题


I use Qt QWebView component which uses flash-player for video playback. How to disable sound on flashplayer executed inside of my QWebView?

One approach that I consider is to execute some javascript code for disabling sound on player, but when to execute it? For example next code disable sound if run it on 1 second after call "load":

page.mainFrame().evaluateJavaScript("""
    var mute_all_tags=function(tag){
        var elems = document.getElementsByTagName(tag);
        for(var i = 0; i < elems.length; i++){
            elems[i].muted=true;
            //alert(elems[i]);
        }
    }
    mute_all_tags("video");
    mute_all_tags("audio");
""")

Earlier calls don't stop sound. Calls on QWebView.loadFinished stops sound but for that moment some sound already issued , how can i stop sound immediately?


回答1:


It sounds like you are loading external pages (i.e. 3rd-party sites) with HTML5 video or Flash video into your QWebView. Also, keeping the videos muted right from the start with absolutely no audio seems like the critical feature you are seeking.

Solution 1

Your page.mainFrame().evaluateJavaScript("...") seems to be the easiest solution, but there will be a lag before this script is executed.

Solution 2

An alternative is to scrape the target website, then using regex or something similar change all the <video> tags to add the mute property e.g. <video controls muted>. Do something analogous for any <embed> tags too. Then, load this modified HTML into the web view with the setHtml() method, also setting the base url, and possibly the referer header. Then the HTML will render with your videos muted from the start.

Solution 3

Another idea might be to intercept media URLs with Qt itself (e.g. .mp4, .mov), and initially hold them in a paused queue, call your page.mainFrame().evaluateJavaScript("...") to programmatically mute the <video> and <audio> tags, then allow the queue to proceed when the evaluateJavaScript() call returns. The media, if auto-playing, should start muted.




回答2:


Please fix your code to following :

page.mainFrame().evaluateJavaScript("var mute_all_tags=function(tag){var elems = document.getElementsByTagName(tag);for(var i = 0; i < elems.length; i++){elems[i].muted=true;}}mute_all_tags('video');mute_all_tags('audio');")

The String in your code is not valid :

  1. You are adding double quotes to string without Concatenation .

  2. You are using double quotes inside double quotes which is a mess.



来源:https://stackoverflow.com/questions/29377139/how-to-disable-sound-on-flashplayer-in-my-custom-application

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