禁用AngularJS中的YouTube视频在Bootstrap模式下播放



我在Bootstrap模态中嵌入了一个YouTube视频。问题是,当用户点击离开模态时,它会关闭,视频会继续播放。我正在尝试添加一些内容,以便检查模态是否关闭,然后停止视频。我试过使用$scope.$watch('videoModalone',但没有成功。

          <div class="modal fade" id="videoModalone" ng-model="youtubeVideo">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title"></h4>
                        </div>
                        <div class="modal-body">
                            <iframe width="550" height="350" src="http://www.youtube.com/embed/mwuPTI8AT7M?rel=0" frameborder="0"></iframe>
                        </div>
                    </div>
                </div>
            </div>

对于那些感兴趣的人来说,这就是我让它工作的方式:

     <div class="modal fade" id="videoModalone">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title"></h4>
                    </div>
                    <div class="modal-body">
                        <iframe width="550" height="350" src="http://www.youtube.com/embed/mwuPTI8AT7M?enablejsapi=1&version=3&playerapiid=ytplayer" frameborder="0"></iframe>
                    </div>
                </div>
            </div>
        </div>

然后在我的控制器中,我寻找模式关闭

$('#videoModalone').on('hide.bs.modal', function () {
    var outerDiv = document.getElementById("videoModalone");
    var youtubeIframe = outerDiv.getElementsByTagName("iframe")[0].contentWindow;
    youtubeIframe.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*'); 
});

这就成功了现在这一切的关键是视频的url?enablejsapi=1&版本=3&playerapiid=ytplayer

对于Bootstrap 5 Modal

ngAfterContentChecked():无效{document.getElementById('videoModalone').addEventListener('hide.bs.modal',function(){const getFrame=this.getElementsByTagName("iframe")[0].contentWindow;getFrame.postMessage('{"event":"command","func":"'+'stopVideo'+'","args":"}','*');});}

相关内容

  • 没有找到相关文章

最新更新