Sound plays every other time the Video plays in Chrome

≯℡__Kan透↙ 提交于 2020-01-04 05:24:07

问题


In chrome (7.0.517.44) I am using the <video> tag and the audio will only play every other time the video is played.

Why is the audio not always playing along with the video?

In page:

<div id="VideoShow">
    <video id="VideoPlay" width=800 height=600></video>
</div>

On click this JS is run.

function playVideo(videoName) {
    $("#VideoShow").fadeIn(300);
    var Vid = document.getElementsByTagName('video')[0];
    Vid.src = videoName;
    Vid.play();
    Vid.addEventListener('ended', function(e) {
        closeVideo();
    }, false);
}

function closeVideo() {
    var Vid = document.getElementsByTagName('video')[0];
    Vid.removeEventListener('ended', arguments.callee, false);
    Vid.pause();
    $("#VideoShow").fadeOut(300);
}

回答1:


I had a very similar problem with the <audio> tag recently. Although I wasn't able to determine the actual cause, I was able to work around the issue by removing the old <audio> element from the DOM and replacing it with an identical element immediately before each call to play().




回答2:


I continue to find inconsistencies with the behavior of these elements.

Have you tried waiting to run the .play() method until after you receive a canplay or canplaythrough event?

Might be worth a shot.



来源:https://stackoverflow.com/questions/4248404/sound-plays-every-other-time-the-video-plays-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!