Reputation: 13458
I have 5 links that opens 5 different videos in the modal window, the following code plays the video in the modal window and stops the video when the modal window is closed.
But, when i try open the same video again the video is disabled in the modal window and no longer playable. Is there a fix for this?
here is modal window code and javascript and fiddle link below
Modal
<div class="modal fade video2 advSearchModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Video 2</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="bs-example" data-example-id="responsive-embed-16by9-iframe-youtube">
<div class="embed-responsive embed-responsive-16by9">
<video class="embed-responsive-item" controls src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" type="video/mp4"> </video>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Send message</button> -->
</div>
</div>
</div>
</div>
JS
$(document).ready(function() {
$(document).ready(function() {
$(".advSearchModal").on('hide.bs.modal', function(evt) {
var player = $(evt.target).find('video'),
vidSrc = player.prop('src');
player.prop('src', ''); // to force it to pause
player.prop('src', vidSrc);
});
});
});
Upvotes: 0
Views: 28
Reputation: 4222
I'm using the following trick to stop HTML5 video. pause() the video on modal close and set currentTime = 0;
$(".advSearchModal").on('hide.bs.modal', function(evt) {
$(evt.target).find('video').get(0).pause();
$(evt.target).find('video').get(0).currentTime = 0;
});
Set currentTime = 0
for when you open modal the video play of the begin.
Upvotes: 1