Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop audio from continuing to play after removing video tag with jQuery?

The audio keeps playing when I use the remove function to remove the video. This doesn't happen if I don't include autoplay as an attribute in the video tag. I tried different things and nothing seems to work.

//$("#video").pause();
//$("#video").stop();
$("#video").empty();
$("#video").remove();
like image 692
Orb Hitter Avatar asked Apr 05 '12 21:04

Orb Hitter


2 Answers

Might be a little late, but I had the same issue and the above answer didn't worked for me (yes the tag was created by jQuery)

I got it working by using

jQuery('#myvideoTag').trigger('pause');
like image 76
John Do Avatar answered Oct 31 '22 19:10

John Do


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 24
Cristian Triviño Avatar answered Oct 31 '22 19:10

Cristian Triviño