html YouTube视频自定义暂停播放按钮,从给定时间开始

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html YouTube视频自定义暂停播放按钮,从给定时间开始相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


</head>
<body>
<center>
<h1>YouTube Video Custom pause play button and a start from a given time</h1>


<br/>
<iframe id="video" src="https://www.youtube.com/embed/rsuqzqbmwcY?enablejsapi=1&html5=1&rel=0&start=5" allowfullscreen=""
        frameborder="0" height="315" width="560"></iframe>

        <br>

        <button id="play-button">Play</button>
        <button  id="pause-button">Pause</button>

</center>
</body>

<script>
    // https://developers.google.com/youtube/iframe_api_reference

    // global variable for the player
    var player;

    // this function gets called when API is ready to use
    function onYouTubePlayerAPIReady() {
        // create the global player from the specific iframe (#video)
        player = new YT.Player('video', {
            events: {
                // call this function when player is ready to use
                'onReady': onPlayerReady
            }
        });
    }

    function onPlayerReady(event) {

        // bind events
        var playButton = document.getElementById("play-button");
        playButton.addEventListener("click", function () {
            player.playVideo();
        });

        var pauseButton = document.getElementById("pause-button");
        pauseButton.addEventListener("click", function () {
            player.pauseVideo();
            alert(player.getCurrentTime());

        });

    }

    // Inject YouTube API script. 
    var tag = document.createElement('script');
    tag.src = "//www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
</script>
</html>

以上是关于html YouTube视频自定义暂停播放按钮,从给定时间开始的主要内容,如果未能解决你的问题,请参考以下文章

为 Youtube 视频添加自定义播放按钮

在自定义按钮单击中播放 iframe 内的 youtube 视频

html Vimeo Video自定义暂停播放按钮,从给定时间开始

在 VideoView 中从暂停状态播放视频

自定义 html5 视频播放器的控件元素中可用的按钮

html youtube 自定义播放按钮