嵌入式Vimeo视频自动播放

时间:2017-11-06 18:08:58

标签: javascript php

我的代码如下,我一个接一个地播放视频,但视频存储在本地,我想在页面上使用集成的vimeo视频,让它们在页面打开和第一个视频时立即开始播放已经完成,第二个开始。 在我的代码中我有一个src的数组(播放列表[])...是否有可能用我的Vimeo视频源替换源?或者没有?

 <video id="headervideo" class="video">
                            <source id="videoFile" width="100%" height="100%" />
                          Your browser does not support the video tag.
                     </video>

      <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
        <script type="text/javascript">
        //==============================
        var track = 0
        var playlist = [{src: 'https://player.vimeo.com/video/240512614?title=0&byline=0&portrait=0&badge=0', type: 'video/mp4'}, {src: 'https://player.vimeo.com/video/240289181', type: 'video/mp4'}]


        //==============================
        $(document).ready(function() {
            document.getElementById('headervideo').addEventListener('ended', function () {
                track++
                track = (track > (playlist.length - 1)) ? 0 : track
                //alert(track)
                playMovie(playlist[track])
            }, false)
            playMovie(playlist[track])
        })
        //==============================
        playMovie = function (movie) {
            $('#videoFile')
                .prop('src', movie.src)
                .prop('type', movie.type)

            document.getElementById('headervideo').load()
            document.getElementById('headervideo').play()
        }
         //==============================
     </script>

1 个答案:

答案 0 :(得分:0)

根据vimeo文档

,也许这可以帮到你

修改

我用一个工作示例替换之前发布的代码

<!DOCTYPE html>

<html>

<head>
    <title></title>
</head>

<body>
    <div id="video-container"></div>
    <script src="https://player.vimeo.com/api/player.js"></script>
    <script>
    document.addEventListener("DOMContentLoaded", function(event) {

        var videos = ['59777392', '19231868', '202791609']; //videos ids

        var options = {
            width: 640
        };

        playMovie(null, videos, options)
    })

    var playMovie = function(player, videos, options) {

        if (!videos.length) {
            return false;
        }

        var video = videos.shift();

        if(!player){
            options.id = video;
            player = new Vimeo.Player('video-container', options);
            player.play();
            player.on('ended', function(){
                playMovie(player, videos, options)
            })
        }else{
            player.loadVideo(video)
                .then(function(){
                    player.play();
                })
                .catch(function(error) {
                    console.warn(error);
                });
        }
    }
    </script>
</body>

</html>

我首先在选项中使用自动播放进行了测试,但它只会自动启动前两个视频。我通过调用每个视频上的播放功能来解决问题