Discover multiple jwplayers on a page

∥☆過路亽.° 提交于 2019-12-24 22:14:16

问题


I need to write some javascript code which will loop through all jwplayers available on a page.

The jwplayer api has a function selectPlayer():

var player = jwplayer.api.selectPlayer();

But this only returns the first player on the page. I can't see a way to find them all?


回答1:


There are a few ways to do this, but the simplest would be to call "jwplayer(x)" - where x is a zero-based index relating to an Array of jwplayers on the page - as this will return the Player instance at that index.

So for JW7 / JW8 you could simply do the following:

var jwpAll = document.querySelectorAll('.jwplayer');
for(var jwpIndex=0,jwpTotal=jwpAll.length;jwpIndex<jwpTotal;jwpIndex++){
    var player = jwplayer(jwpIndex);
}


来源:https://stackoverflow.com/questions/46733833/discover-multiple-jwplayers-on-a-page

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