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

how to change vimeo video source to local mp4 video using javascript

本文关键字:视频 mp4 何使用 javascript vimeo      更新时间:2023-09-26

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

这是我的代码:

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();
]);

这里有两个事件:

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