【问题标题】:how to change vimeo video source to local mp4 video using javascript如何使用 javascript 将 vimeo 视频源更改为本地 mp4 视频
【发布时间】:2014-10-01 10:32:30
【问题描述】:

我正在尝试制作一个包含 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();
]);

【问题讨论】:

  • 我对我的 javascript 编码进行了一些调整,但仍然无法更改视频源。这是我的 js 代码:

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


【解决方案1】:

所以有两个事件:

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

【讨论】:

    猜你喜欢
    • 2011-02-27
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    相关资源
    最近更新 更多