Video.js - How to reference multiple videos in one

2019-04-13 08:06发布

My goodness, I cannot find an answer for this and I spent several hours already. How can you reference multiple videos at the same time in video.js?

The API documentation says:

Referencing the Player: You just need to make sure your video tag has an ID. The example embed code has an ID of "example_video_1". If you have multiple videos on one page, make sure every video tag has a unique ID.

var myPlayer = V("example_video_1");

This example shows a single ID, but it doesnt show how I can reference multiple IDs at the same time.

If I have 3 different tags: "video_1", "video_2", "video_3", how do I reference them all?

I tried an array and it didnt work. I also tried listing the videos like this:

var myPlayer = _V_("video_1", "video_2");

and didnt work neither.

Can somebody help me here?

Thank you.

2条回答
够拽才男人
2楼-- · 2019-04-13 08:40

This would also work:

var video = [];
video[1] = _V_("Video1");
video[2] = _V_("Video2");
video[3] = _V_("Video3");
video[4] = _V_("Video4");
video[5] = _V_("Video5");
video[6] = _V_("Video6");
video[7] = _V_("Video7");
video[8] = _V_("Video8");
video[9] = _V_("Video9");
video[10] = _V_("Video10");
查看更多
姐就是有狂的资本
3楼-- · 2019-04-13 08:49

You can't pass multiple ids to _V_(). Either do them one at a time:

var myPlayer1 = _V_("video_1");
var myPlayer2 = _V_("video_2");
var myPlayer3 = _V_("video_3");

Or if you want them as an array:

var myPlayers = Array(_V_("video_1"), _V_("video_2"), _V_("video_3"));
myPlayers[1].play();

Note: this was written for an older version of video.js. _V_() still works but is deprecated: use videojs() instead.

查看更多
登录 后发表回答