为 HTML5 视频创建自定义音量控制时出现问题
我正在开发一个相当复杂的项目,需要自定义音量滑块来控制 HTML5 视频元素。我将音量控制简化为一个非常简单的示例,我认为没有理由它不工作。我希望对以下代码有任何见解:
jQuery:
<script>
$(function() {
$('#volume').change(function () {
newvolume = $('#volume').attr("value") / 100;
$('#video').attr("volume", newvolume);
console.log($('#video').attr("volume"));
});
});
</script>
HTML:
<video id="video" controls="controls">
<source src="http://dev.domain.com/media/16514.m4v">
</video>
<input id="volume" type="range" min="0" max="100" value="100" />
应该注意的是,除了视频剪辑上音量的可听变化之外,这一切似乎都有效。即使console.log结果返回正确的值(0到1.00)我也尝试过严格的Javascript版本,即videoElement.volume = newvolume
如果它很重要,我正在Safari 5.1中进行测试.2.
I have a fairly complex project in the works that requires a custom volume slider to control an HTML5 video element. I've boiled the volume control down to a very simple example and I see no reason why it should not be working. I would love any insight regarding the following code:
jQuery:
<script>
$(function() {
$('#volume').change(function () {
newvolume = $('#volume').attr("value") / 100;
$('#video').attr("volume", newvolume);
console.log($('#video').attr("volume"));
});
});
</script>
HTML:
<video id="video" controls="controls">
<source src="http://dev.domain.com/media/16514.m4v">
</video>
<input id="volume" type="range" min="0" max="100" value="100" />
It should be noted that every aspect of this appears to work except an audible change in volume on the video clip. Even the console.log result is returning the correct value (0 through 1.00) I have also tried the strictly Javascript version of this, i.e. videoElement.volume = newvolume
If it's significant, I am testing in Safari 5.1.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
$('#video').attr("volume", newvolume);
,请尝试以下操作:如果没记错的话,
volume
不是的属性HTML5 中的 video
只能通过 DOM 元素本身访问。Instead of
$('#video').attr("volume", newvolume);
, try this:If memory serves,
volume
is not an attribute ofvideo
in HTML5, it is only accesible via the DOM element itself.