Answer the question
In order to leave comments, you need to log in
How to play HTML 5 video from the beginning using JS?
Is there a video:
<video loop="loop" preload="auto" class="page_header__video_item" id="video_bg" autoplay muted>
<source media="only screen" type="video/mp4" src="/theme/edsro/video.mp4" id="mp4">
</video>
$('.play').click(function() {
if ( $("video").prop('muted' )) {
$("video").prop('muted', false);
$(this).addClass('active');
} else {
$("video").prop('muted', true);
$(this).removeClass('active');
}
return false;
});
Answer the question
In order to leave comments, you need to log in
jsfiddle.net/edajzoqm
// получаем элемент видео
var video = document.getElementById('video');
// Флаг, по которому будем понимать, что выходим из mute
var wasMuted = video.muted;
// Время воспроизведения, на которое выставить
var unmuteTime = 0;
video.onvolumechange = function() {
if (wasMuted) {
// Было в состоянии mute
wasMuted = false;
// ставим необходимое время
video.currentTime = unmuteTime;
} else if (video.muted) {
// Юзер включил mute
wasMuted = true;
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question