player.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var xg_player=null;
  2. /* 单个切换播放 */
  3. function xgPlay(htmlid,pull,stream='',data={}){
  4. if(xg_player){
  5. var par=document.getElementById(htmlid).parentNode;
  6. xg_player.destroy(false);
  7. //xg_player.pause();
  8. par.innerHTML ='<div id="'+htmlid+'"></div>';
  9. }
  10. xg_play(htmlid,pull,stream,data);
  11. }
  12. /* 多个同时播放 */
  13. function xgPlays(htmlid,pull,stream,data={}){
  14. xg_play(htmlid,pull,stream,data);
  15. }
  16. function xg_play(htmlid,pull,stream,data={}){
  17. if(htmlid=='' || pull==''){
  18. return !1;
  19. }
  20. var last_len=pull.lastIndexOf(".")+1;
  21. var last_len2=pull.lastIndexOf("?");
  22. var len = pull.length;
  23. if(last_len2>0){
  24. len=last_len2;
  25. }
  26. var pathf = pull.substring(last_len,len).toLowerCase();
  27. //console.log(pull);
  28. var data_play={
  29. "id": htmlid,
  30. "url": pull,
  31. "volume":0.2,
  32. "width":'100%',
  33. "height":'100%',
  34. "ignores": ['time','replay'],
  35. autoplay:false,
  36. };
  37. data_play= $.extend(data_play, data); //jq 合并对象
  38. if(pathf=='flv'){
  39. // xg_player=new FlvJsPlayer(data_play);//--未升级版本
  40. let xg_player = new window.FlvJsPlayer(data_play);
  41. //视频开始播放事件
  42. xg_player.on('play',function(){
  43. //alert("视频开始播放了!");
  44. })
  45. xg_player.on('pause',function(){
  46. //alert("视频暂停了!");
  47. })
  48. return !0;
  49. }else if(pathf=='m3u8'){
  50. //xg_player=new HlsJsPlayer(data_play); //--未升级版本
  51. let xg_player=new window.HlsJsPlayer(data_play);
  52. return !0;
  53. }else{
  54. // xg_player=new Player(data_play); //--未升级版本
  55. let xg_player=new Player(data_play);
  56. return !0;
  57. }
  58. }