如何在我的自定义应用程序禁用Flashplayer的声音? [英] How to disable sound on flashplayer in my custom application?

查看:267
本文介绍了如何在我的自定义应用程序禁用Flashplayer的声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Qt QWebView组件,它使用Flash播放器来播放视频。如何在我的QWebView内部执行的Flashplayer上禁用声音?



我考虑的一种方法是执行一些JavaScript代码来禁用播放器上的声音,但何时执行它?例如,下一个代码禁用声音,如果在调用load之后1秒钟运行它:

  page.mainFrame()。evaluateJavaScript (变量i = 0; i< elems.length; i ++){
var mute_all_tags = function(tag){
var elems = document.getElementsByTagName(tag);

elems [i] .muted = true;
// alert(elems [i]);
}
}
mute_all_tags(video);
mute_all_tags(audio);

不要停止声音。呼吁QWebView.loadFinished停止声音,但在那一刻已经发出一些声音,我怎么能立即停止声音?

解决方案

听起来好像是用HTML5视频或Flash视频将外部网页(即第三方网站)加载到QWebView中。此外,从一开始就保持视频静音,绝对没有音频看起来像你正在寻找的关键功能。

解决方案1 ​​



您的 page.mainFrame()。evaluateJavaScript(...)似乎是最简单的解决方案,但是在脚本之前会有滞后执行。

解决方案2



另一种方法是刮目标网站,然后使用正则表达式或类似的改变所有< video> 标记添加静音属性,例如< video controls muted> 。对于任何< embed> 标签也做类似的事情。然后,使用 setHtml()方法将修改后的HTML加载到Web视图中,同时设置基本URL和可能的referer头。然后,HTML将从您的视频静音开始呈现。



解决方案3



另一个想法可能是用Qt本身拦截媒体URL(例如.mp4,.mov),最初把它们保存在暂停的队列中,调用你的 page.mainFrame()。evaluateJavaScript(...)以编程方式静音< video> < audio> 标签,然后允许队列继续当 evaluateJavaScript()调用返回时。媒体,如果自动播放,应该开始静音。


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?

解决方案

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.

这篇关于如何在我的自定义应用程序禁用Flashplayer的声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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