通过 JavaScript 增加 (youtube flash) 视频的音量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6885776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Increase (youtube flash) video's sound volume by means of JavaScript
提问by BogdanSorlea
Background story: many users (including me) browse the web from notebooks that are not constructed for sound performance. That means (besides other things) that the sound volume for most videos is too low, especially if the video itself is recorded at low volume.
背景故事:许多用户(包括我)从不是为声音性能而构建的笔记本电脑浏览网页。这意味着(除其他外)大多数视频的音量太低,特别是如果视频本身以低音量录制。
Therefore...
因此...
I was wondering if there is any way of increasing the volume of such a video (especially Youtube, but could be extended to other types), because I'm interested in doing it and even publishing it as Firefox/Chrome/other browser plug-in.
我想知道是否有任何方法可以增加此类视频的音量(尤其是 Youtube,但可以扩展到其他类型),因为我有兴趣这样做,甚至将其发布为 Firefox/Chrome/其他浏览器插件-在。
Or, alternatively, if you know such a plug-in do not hesitate to post the link here.
或者,如果您知道这样的插件,请不要犹豫在此处发布链接。
采纳答案by serg
If you want to control system volume then JavaScript has no direct access to it, you would need to write NPAPI (C++ dll) plugin.
如果您想控制系统音量,那么 JavaScript 无法直接访问它,您需要编写 NPAPI (C++ dll) 插件。
If you want to just adjust video player's own volume (you won't be able to increase it beyond 100%) then JavaScript can do it, perhaps.
如果您只想调整视频播放器自身的音量(您将无法将其提高到 100% 以上),那么 JavaScript 或许可以做到。
If video player is HTML5 <video>
tag then controlling volume is easy. For YouTube it would be:
如果视频播放器是 HTML5<video>
标签,那么控制音量很容易。对于 YouTube,它将是:
document.getElementsByClassName("video-stream")[0].volume = 0.5; //50%
If it is a custom made flash player then you need to rely on its JavaScript interface, if any. Youtube player happens to support controlling volume with JavaScript:
如果它是一个定制的 Flash 播放器,那么你需要依赖它的 JavaScript 接口(如果有的话)。Youtube 播放器恰好支持使用 JavaScript 控制音量:
document.getElementById("movie_player").setVolume(50);
In order for this to work you would need to break out of extension sandbox first by injecting <script>
tag on the page with this code.
为了使其工作,您需要首先通过<script>
使用此代码在页面上注入标记来突破扩展沙箱。
There is no universal solution, you would need to deal with each site individually.
没有通用的解决方案,您需要单独处理每个站点。
回答by Marco
Use VLC Media Player. You can copy and paste links into it. Increase sound to up to 250%
使用 VLC 媒体播放器。您可以将链接复制并粘贴到其中。将声音提高到 250%
回答by Wladimir Palant
You can use js-ctypesto change system's volume level. Here is an example that sets volume to 12.5%:
您可以使用js-ctypes来更改系统的音量级别。以下是将音量设置为 12.5% 的示例:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("winmm.dll");
var waveOutSetVolume = lib.declare("waveOutSetVolume", ctypes.default_abi,
ctypes.uint32_t,
ctypes.int32_t, ctypes.uint32_t);
waveOutSetVolume(-1, 0x20002000);
lib.close();
However, this only changes the volume for the Firefox process. It won't have any effect on Flash because it runs in a different process now. I'm not even sure whether winmmhas some way to change the global volume at all, you might need the new MMDevice APIfor that - and then it gets complicated because doing COM calls via js-ctypes IMHO isn't possible. Only option is creating your own library to be distributed along with your extension. That should do the COM messaging and export a plain API that can be called via js-ctypes.
但是,这只会更改 Firefox 进程的音量。它不会对 Flash 产生任何影响,因为它现在在不同的进程中运行。我什至不确定winmm是否有某种方法来改变全局音量,您可能需要新的MMDevice API- 然后它变得复杂,因为通过 js-ctypes 恕我直言进行 COM 调用是不可能的。唯一的选择是创建您自己的库以与您的扩展一起分发。这应该执行 COM 消息传递并导出可以通过 js-ctypes 调用的普通 API。
回答by user5959285
You can use Sound Booster software by Letasoft, but there are some things you might encounter like crash, we are using netbooks so the built-in sound card has limit. So try to buff first before playing that's the best advice that I can give. The max volume output will be 500%.
您可以使用 Letasoft 的 Sound Booster 软件,但是您可能会遇到一些问题,例如崩溃,我们使用的是上网本,因此内置声卡有限制。所以在玩之前先尝试buff,这是我能给出的最好的建议。最大音量输出将为 500%。