gpt4 book ai didi

javascript - 无法选择视频

转载 作者:可可西里 更新时间:2023-11-01 13:42:36 25 4
gpt4 key购买 nike

我正在尝试将我的视频静音/取消静音。但首先,我似乎无法选择我的视频。尝试过教程示例和类似问题的答案,但它们都指向相同的选择视频的方式。请指教这里有什么问题。谢谢。

<!-- HTML -->
<button id="enableMute" onclick="enableMute()" type="button">Mute</button>
<button id="disableMute" type="button">Enable</button>
<button id="checkMute" type="button">Status</button><br>

<video id="myVideo" width="320" height="176" autoplay loop muted>
<source src="video/trailer.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>

<!-- JS -->
$(function() {
// seems not being selected. Tried without hash and same result.
var vid = $("#myVideo");

//alert works but clearly nothing happening with mute controls
$("#enableMute").click(function(){
alert("enableMute");
vid.muted = true;
vid.volume = 1.0;
});

//alert works but clearly nothing happening with mute controls
$("#disableMute").click(function(){
alert("disableMute");
vid.muted = false;
vid.volume = 1.0;
});

//if i click this button first, the alert is "alert undefined"
$("#checkMute").click(function(){
alert('alert: ' + vid.muted);
});
});

最佳答案

正在选择视频并将其放入变量中。使用 .muted 将不起作用,您需要使用 jQuery 的 .prop() 函数,正如我在 this question 中发现的那样.这应该有效:

HTML

<button id="enableMute" onclick="enableMute()" type="button">Mute</button>
<button id="disableMute" type="button">Enable</button>
<button id="checkMute" type="button">Status</button><br>

<video id="myVideo" width="320" height="176" autoplay loop muted>
<source src="video/trailer.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>

JavaScript

$(function() {
// Video is being selected
var vid = $("#myVideo");

$("#enableMute").click(function() {
alert("enableMute");
vid.prop('muted', true);
vid.prop('volume', 1.0);
});

$("#disableMute").click(function() {
alert("disableMute");
vid.prop('muted', false);
vid.prop('volume', 1.0);
});

$("#checkMute").click(function() {
alert('alert: ' + vid.prop('muted'));
});
});

要通过示例视频查看它的实际效果,请转至 this link .

关于javascript - 无法选择视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52797944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com