VideoJS:动态更改视频网址时,mp4无效

时间:2016-04-20 09:14:46

标签: javascript angularjs html5 coffeescript video.js

我正在使用videoJs来播放视频。

HTML

<video id="player-vjs_html5_api" class="vjs-tech" crossorigin="anonymous" preload="auto" src="http://path-to-video/small.mp4">
  <p class="vjs-no-vjs">Your browser does not support video.</p>
</video>

的Javascript

  loadMedia: function(path) {
    player.src(path);
    return void 0;
  }

当我使用.webm但我尝试使用mp4时出现以下错误

VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported. 

我也试过了,但它没有工作

<video id="player-vjs_html5_api" class="vjs-tech" crossorigin="anonymous" preload="auto">
    <source src="" type="video/mp4" />
    <source src="" type="video/webm" />
    <source src="" type="video/ogv" />
  <p class="vjs-no-vjs">Your browser does not support video.</p>
</video>

  loadMedia: function(path) {
    player.src([
        { type: "video/mp4", src: path+".mp4" },
        { type: "video/webm", src: path+".webm" },
        { type: "video/ogg", src: path+".ogv" }
    ]);
    return void 0;
  }

但它也没有用。

1 个答案:

答案 0 :(得分:0)

当我做了以下更改时,它有效。刚删除crossorigin="anonymous"

<video id="player-vjs_html5_api" class="vjs-tech" preload="auto">
    <source src="" type="video/mp4" />
    <source src="" type="video/webm" />
    <source src="" type="video/ogv" />
  <p class="vjs-no-vjs">Your browser does not support video.</p>
</video>

的javascript

loadMedia: function(path) {
    player.src([
        { type: "video/mp4", src: path+".mp4" },
        { type: "video/webm", src: path+".webm" },
        { type: "video/ogg", src: path+".ogv" }
    ]);
    return void 0;
  }