Reputation: 661
I have a muted
video tag with a src
. I'm able to un-mute the video programmatically, but not if I change the src
at the same time (order irrelevant). Any ideas why that may be? Here's an example:
setTimeout(function(){
// If you comment out this line and src doesn't change, it works.
$('#video').prop('src', 'http://webm.land/media/1KM9.webm');
$('#video').prop('muted', false);
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />
Upvotes: 0
Views: 118
Reputation: 36609
Remove both
attribute
andproperty
"muted"
from the element as even if attribute is removed,property
remainstrue
!
setTimeout(function() {
$('#video').removeAttr('muted');
console.log($('#video').prop('muted'));
$('#video').prop('muted', false);
$('#video').prop('src', 'http://webm.land/media/1KM9.webm');
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted="muted" src="http://webm.land/media/KLNV.webm" width="400" height="200" />
Upvotes: 2
Reputation: 1821
setTimeout(function() {
$('#video').removeAttr('muted');
$('#video').prop('src', 'http://webm.land/media/1KM9.webm');
document.getElementById('video').muted = false;
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />
It works!
Upvotes: 3
Reputation: 1
Try removing muted
attribute using .removeAttr()
, .clone()
original jQuery object, replacing original <video>
element with cloned element with .replaceWith()
setTimeout(function(video){
video.replaceWith(video.clone().removeAttr("muted")
.prop("src", "http://webm.land/media/1KM9.webm"))
}, 3000, $("#video"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />
Upvotes: -1