Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio continues after removing <video> element in Chrome

I am having issues with video support in Chrome. My web page must run in Chrome and I am using the following code to check periodically if the web page has to play a video or not... but the problem is that after I remove the element, I still hear the audio and when I recreate the eleemnt, the audio of the new video and the old overlaps.

function showVideo() {
        var video = videodata;

        var videobox = $('#videobox').first();
        var videoplayer = $('#videoplayer').first();

        if (video.Enabled) {
            if ((videoplayer.length > 0 && videoplayer[0].currentSrc != video.Location) || videoplayer.length == 0) {
                videobox.empty();
                videobox.append('<video id="videoplayer" preload="auto" src="' + video.Location + '" width="100%" height="100%" autoplay="autoplay" loop="loop" />');
                videobox.show();
            }
        } else {
            videobox.hide();
            videobox.empty(); // Clear any children.
        }
    }

How can I solve?

Thank you.

like image 845
Umar Jamil Avatar asked Jan 28 '12 13:01

Umar Jamil


2 Answers

The following was the minimum I had to go to get this to work. I was actually experiencing a stall due to the buffering while spawning ajax requests when the user pressed the back button. Pausing the video in Chrome and the Android browser kept it buffering. The non-async ajax request would get stuck waiting for the buffering to finish, which it never would.

Binding this to the beforepagehide event fixed it.

 $("#SOME_JQM_PAGE").live("pagebeforehide", function(event)
 {
           $("video").each(function () 
           { 
               logger.debug("PAUSE VIDEO");
               this.pause();
               this.src = "";
           });
 });

This will clear every video tag on the page.

like image 140
Halsafar Avatar answered Oct 04 '22 15:10

Halsafar


firsly try to create "video" tag empty in the html and create "source" tag into javascript code

<html>
.
.
<video id="main-video" autoplay=""></video>
.
.
</html>


<script>
   $('#main-video').append('<source type="video/mp4" src="URL.mp4">');
</script>
like image 45
Cristian Triviño Avatar answered Oct 04 '22 16:10

Cristian Triviño