Html HTML5 视频音量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2602541/
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
HTML5 Video Volume
提问by Mikushi
I'm currently working on an HTML5 video player, I have it working fully everywhere, except on the iPad.
Basically, I can control everything, except the sound, I have a mute
button, it works fine on Google Chrome, Firefox 3.6 and Safari on Mac OS, but on the iPad no matter what value I put in video.volume
, there is no change happening.
我目前正在开发一个 HTML5 视频播放器,除 iPad 外,它在任何地方都能正常工作。基本上,我可以控制一切,除了声音,我有一个mute
按钮,它在 Mac OS 上的 Google Chrome、Firefox 3.6 和 Safari 上运行良好,但在 iPad 上,无论我输入什么值video.volume
,都没有发生任何变化。
Did anybody get it working properly?
有人让它正常工作吗?
Here's my HTML code:
这是我的 HTML 代码:
<video src="video_url" width="608" height="476" autobuffer="autobuffer" id="html5-player" preload>
Your browser doesn't support HTML5.
</video
And here's the Javascript:
这是 Javascript:
var muted = false;
$j('.player-mute').click(function(){
if(muted) {
videoPlayer.volume = 1;
muted = false;
} else {
videoPlayer.volume = 0;
muted = true;
}
});
回答by Dobrin
The volume
property on the iOS devices is read-onlyaccording to Apple's documentation:
在volume
对iOS设备属性为只读根据苹果的文档:
On iOS devices, the audio level is always under the user's physical control. The volume property is not settable in JavaScript. Reading the volume property always returns 1.
在 iOS 设备上,音频电平始终在用户的物理控制之下。音量属性在 JavaScript 中不可设置。读取 volume 属性总是返回 1。
回答by jamone
If you read the iPad html5 video documentation it says that only the user of the device can start video, and change volume.
如果您阅读 iPad html5 视频文档,它会说只有设备用户才能启动视频并更改音量。
回答by Paul
As @dobrin said, the volume
property is read only on IOS for the video.
正如@dobrin 所说,该volume
属性在视频的 IOS 上是只读的。
However, you could use the muted
property, this allow you to mute or unmute video, most of the time, this will respond to the problem.
但是,您可以使用该muted
属性,这允许您将视频静音或取消静音,大多数情况下,这将解决问题。
So, you can't set a specific volume between 0 and 1 but you can set the volume either to 0 or 1, then Apple assume that you will use the physical buttons for setting the volume.
因此,您不能在 0 和 1 之间设置特定音量,但可以将音量设置为 0 或 1,然后 Apple 假设您将使用物理按钮来设置音量。
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/muted
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/muted
回答by Blagodov Pavel
var muted = false;
$j('.player-mute').click(function(){
if(muted) {
videoPlayer.volume(1);
muted = false;
} else {
videoPlayer.volume(0);
muted = true;
}
});
use like function
使用like函数