关于videoJs遇到的坑(一个页面有多个视频需要加载)

涉及到课程的视频:有多节课选择

废话不多说直接上代码:

 var videoPlayer = $("#my-video").get(0);
 if (typeof (videoPlayer) != "undefined") {
    var myPlayer = videojs('my-video');
        myPlayer.dispose();
    }

先判断之前有没有实例化过videoJs,实例化过的话就需要dispose()这个方法销毁实例化的对象;

之后在动态添加:

            var id = "my-video";
            $("#my-wrap").html("<video id='" + id + "' class='video-js' controls preload='none' width='1280px' height='' poster='' ><source id='video-source' src='' type='video/mp4'></video>");
            //设置资源路径
            $("#my-wrap").attr("src", $scope.videoUrl);
            videojs(id, {}, function () { //自动播放
                // Player (this) is initialized and ready.
                var myPlayer = videojs(id);
                videojs(id).ready(function () {
                    var myPlayer = this;
                    myPlayer.play();
                });
                videojs(id).on("click", function () {
                    if (myPlayer.paused()) {
                        $(".vjs-has-started .vjs-big-play-button").show();
                    } else {
                        $(".vjs-has-started .vjs-big-play-button").hide();
                    }
                })
            });

这样即可以实现视频页面 课程的切换

猜你喜欢

转载自blog.csdn.net/qq_39511525/article/details/83146099