Video.js - How to reference multiple videos in one page?

扶醉桌前 提交于 2019-12-06 10:31:26

问题


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.


回答1:


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.




回答2:


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");


来源:https://stackoverflow.com/questions/15084690/video-js-how-to-reference-multiple-videos-in-one-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!