首页 > 解决方案 > 如何在这个 JavaScript 播放器中嵌入 youtube 视频?”

问题描述

我需要在这个播放器上放一个 YouTube 视频:https ://www.w3schools.com/html/mov_bbb.mp4 我必须嵌入一个 youtube 视频我不知道该怎么做

如果有人可以帮助我,我是编程新手

<center><div id="myVideoSources" style="display:none;">
    


<source class="active" src="https://www.w3schools.com/html/mov_bbb.mp4" id="videoSource" type="video/mp4" startat="00:00:00" endat="00:00:10" name="Something" description="This is Gujarati Videol">
    <source class="active" src="https://lh3.googleusercontent.com/lKr008DzBwztuG0f15-hzojP7ACJOlV10WrcFfhp9SWCok4igE4nT
tkCpcETaxvGF5m5tMgZPhkCPyiiueqcdV6d6yR3lM3ERPfRz5jkvrsM_y3xjq1o3GLnazLBEEOUaAbMS86y4g=m22" id="videosource2" type="video/mp4" startat="00:00:00" endat="03:02:02" name="PHP Video " description="This is PHP Video">
  
   </div>

<video id="media-video" controls width="340" height="200"></video>
<script>
    $(function () {
        var sources = $("#myVideoSources source");
        var jVideo = $("#media-video");
        var currentVideoNum = 0;
        loadNextVideo();

        jVideo.bind("ended", function () {
            loadNextVideo();
        });

        function loadNextVideo() {
            var source = $(sources.get(currentVideoNum));
            currentVideoNum++;
            if(currentVideoNum >= sources.length) {
                currentVideoNum = 0;
            }

            jVideo.html("");
            jVideo.append(source);
            var plainVideo = jVideo.get(0);
            plainVideo.load();

            plainVideo.play();
            plainVideo.currentTime = getStartTime(source);
        }

        function getStartTime(source) {
            var time = 0;
            try {
                var startAtStr = source.attr("startat");
                time = startAtStr.split(":");
                time = (time[0] * 3600) + (time[1] * 60) + (time[2] * 1)
            } catch(e) {
                console.log(e);
                time = 0;
            }
            return time;
        }
    });
</script></center>

标签: javascriptvideoyoutube

解决方案


推荐阅读