videojs以编程方式更改音轨

时间:2018-03-30 05:24:37

标签: javascript html5 video.js mediaelement

我已经阅读过两次文档,但还没有找到办法。 videojs本身不能这样做,这在文档中提到,所以我有hls插件应该可以做到但我无法找到与此相关的任何内容。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:3)

以下是使用video.js更改源视频轨道的示例:

public class Login extends AppCompatActivity {

@Bind(R.id.tv_forgot_pass)
    Button button;

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);


}

@OnClick(R.id.tv_forgot_pass)
public void forgotPassClick(){
        Context mContext = LoginActivity.this;
        Class nextActivity = ForgotPasswordActivity.class;
        Intent mIntent = new Intent(mContext, nextActivity);
        startActivity(mIntent);
        finish();
    }
}
/* video player setup */
vPlayer = videojs('my_video', {
  techOrder: ["html5", "youtube"],
  autoplay: false,
  sources: [{
    type: "video/mp4",
    src: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
  }]
});
vPlayer.on('playing', function(e) {
  $("#info").html("playing...<br>url: " + vPlayer.currentSrc() + "<br>type:" + vPlayer.currentType());
});

/* available videos */
var vids = [{
    type: "video/mp4",
    src: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
  },
  {
    type: "video/mp4",
    src: "https://vjs.zencdn.net/v/oceans.mp4"
  },
  {
    type: "video/youtube",
    src: "https://www.youtube.com/watch?v=kkGeOWYOFoA"
  }
];

playVideo = function(n) {
  vPlayer.src(vids[n]);
  vPlayer.play();
}

这里也是一个jsfiddle:https://jsfiddle.net/beaver71/w7yah2vo/