为 HTML5 视频创建自定义音量控制时出现问题

发布于 2024-12-26 12:57:32 字数 790 浏览 2 评论 0原文

我正在开发一个相当复杂的项目,需要自定义音量滑块来控制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2025-01-02 12:57:32

而不是 $('#video').attr("volume", newvolume);,请尝试以下操作:

$('#video')[0].volume = newvolume;

如果没记错的话,volume 不是 的属性HTML5 中的 video 只能通过 DOM 元素本身访问。

Instead of $('#video').attr("volume", newvolume);, try this:

$('#video')[0].volume = newvolume;

If memory serves, volume is not an attribute of video in HTML5, it is only accesible via the DOM element itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文