如何使用javascript将vimeo视频源更改为本地mp4视频

时间:2014-08-08 02:14:35

标签: javascript html5 vimeo video.js video-player

我正在尝试制作一个包含vimeo和本地视频的视频播放器,但如果vimeo视频无法播放,我不知道如何将视频源切换到本地视频。我正在使用video.js.any帮助请:)

这是我的编码:

HTML

<video id="vid1" src="" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360">

使用Javascript:

videojs('vid1', { "techOrder": ["vimeo"], "src": "https://vimeo.com/63186969" }).ready(function() {
// You can use the video.js events even though we use the vimeo controls
// As you can see here, we change the background to red when the video is paused and set it back when unpaused
this.on('pause', function() {
  document.body.style.backgroundColor = 'red';
});

this.on('play', function() {
  document.body.style.backgroundColor = '';
});

// You can also change the video when you want
// Here we cue a second video once the first is done
this.one('ended', function() {
  this.src('http://video-js.zencoder.com/oceans-clip.mp4');
  this.play();
});

我对我的js进行了一些更改,但仍然无法更改。最新的javascript ..请帮助我:)

使用Javascript:

videojs('vid2', { "techOrder": ["vimeo"], "src": "https://vimeo.com/63186969" }).ready(function() {
    // You can use the video.js events even though we use the vimeo controls
    // As you can see here, we change the background to red when the video is paused and set it back when unpaused
    this.on('pause', function() {
        document.body.style.backgroundColor = 'red';
    });

    this.on('play', function() {
        document.body.style.backgroundColor = '';
    });

    // You can also change the video when you want
    // Here we cue a second video once the first is done
    this.one('ended', function() {
        this.src('http://vimeo.com/79380715');
        this.play();
    });   

    myPlayer.src("http://video-js.zencoder.com/oceans-clip.mp4");
    var myPlayer = videojs('vid2');
    myPlayer.ready(function(){ /*Video is ready*/ });
    myPlayer.error(function(){ /*An error happened*/ });
    mpPlayer.play();
]);

1 个答案:

答案 0 :(得分:0)

所以有2个事件:

var myPlayer = videojs('example_video_1');
myPlayer.ready(function(){ /*Video is ready*/ });
myPlayer.error(function(){ /*An error happened*/ });

更多api信息:https://github.com/videojs/video.js/blob/master/docs/api/vjs.Player.md