dplayer + m3u8+ p2p加速

发布时间:2020-07-21 21:00:16 作者:Mos 阅读量:14447

原文地址:https://www.i847.cn/article/19.html

接口地址:https://movie.i847.cn/dplayer/?url=

接口实例:https://movie.i847.cn/dplayer/?url=https://youku.cdn7-okzy.com/20200322/18040_bb9db323/index.m3u8

1、打开 CDNBye OMS  注册账号。添加域名-认证域名。按照里面步骤来即可。

2、php代码:

  1. <html>
  2. <head>
  3. <title>847默认播放器</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=11" />
  6. <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport">
  7. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dplayer@latest/dist/DPlayer.min.css" />
  8. <style type="text/css">
  9. body,html{width:100%;height:100%;background:#000;padding:0;margin:0;overflow-x:hidden;overflow-y:hidden}
  10. *{margin:0;border:0;padding:0;text-decoration:none}
  11. #stats{position:fixed;top:5px;left:10px;font-size:9px;color:#fdfdfd;z-index:20719029;text-shadow:1px 1px 1px #000, 1px 1px 1px #000}
  12. #dplayer{position:inherit}
  13. .dplayer-logo{left:5px; top:12px;}
  14. .dplayer-logo img{width:28px;}
  15. </style>
  16. </head>
  17. <body style="background:#000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" oncontextmenu=window.event.returnValue=false>
  18. <div id="dplayer"></div>
  19. <div id="stats"></div>
  20. <script src="https://cdn.jsdelivr.net/npm/cdnbye@latest"></script>
  21. <script src="https://cdn.jsdelivr.net/npm/dplayer@latest"></script>
  22. <script>
  23. var url = '<?php echo($_REQUEST['url']);?>';
  24. var isWap = false;
  25. if(!isWap){
  26. if(url.indexOf(".m3u8") > 0){
  27. var _peerId = '', _peerNum = 0, _totalP2PDownloaded = 0, _totalP2PUploaded = 0;
  28. var type = 'customHls';
  29. }
  30. else {
  31. var type = 'normal'; //MP4格式P2P兼容性不好,不调用P2P。
  32. }
  33. type = "customHls";
  34. var dp = new DPlayer({
  35. container: document.getElementById('dplayer'),
  36. autoplay: true,//自动播放
  37. lang:"zh-cn",//语言
  38. screenshot:true,//截图
  39. hotkey: true, //热键
  40. preload:"auto",//预加载
  41. logo: '/favicon.png',
  42. video: {
  43. url:url,
  44. pic: '', //封面
  45. type: type,
  46. customType: {
  47. 'customHls': function (video, player) {
  48. const hls = new Hls({
  49. debug: false,
  50. p2pConfig: {
  51. logLevel: true,
  52. live: false, // 如果是直播设为true
  53. }
  54. });
  55. hls.loadSource(video.src);
  56. hls.attachMedia(video);
  57. hls.p2pEngine.on('stats', function (stats) {
  58. _totalP2PDownloaded = stats.totalP2PDownloaded;
  59. _totalP2PUploaded = stats.totalP2PUploaded;
  60. updateStats();
  61. }).on('peerId', function (peerId) {
  62. _peerId = peerId;
  63. }).on('peers', function (peers) {
  64. _peerNum = peers.length;
  65. updateStats();
  66. });
  67. }
  68. }
  69. },
  70. danmaku: {
  71. id: 'efbd974184da4819ab0cc068234a50d3', //弹幕id,随意一个唯一的
  72. api: 'https://dplayer.moerats.com/',//弹幕api 固定
  73. bottom: '25%',
  74. unlimited: true,
  75. },
  76. contextmenu: [
  77. {
  78. text: '847影视',
  79. link: 'https://movie.i847.cn',
  80. },
  81. ],
  82. });
  83. var webdata = {
  84. set:function(key,val){
  85. window.sessionStorage.setItem(key,val);
  86. },
  87. get:function(key){
  88. return window.sessionStorage.getItem(key);
  89. },
  90. del:function(key){
  91. window.sessionStorage.removeItem(key);
  92. },
  93. clear:function(key){
  94. window.sessionStorage.clear();
  95. }
  96. };
  97. dp.seek(webdata.get('vod'+url));
  98. setInterval(function(){
  99. webdata.set('vod'+url,dp.video.currentTime);
  100. },1000);
  101. dp.on('ended',function() {
  102. dp.notice("视频播放已结束");
  103. if(parent.MacPlayer.PlayLinkNext!=''){
  104. top.location.href = parent.MacPlayer.PlayLinkNext;}
  105. });
  106. }
  107. else{
  108. document.getElementById('dplayer').innerHTML='<video src="'+url+'" controls="controls" preload="preload" poster="" width="100%" height="100%" autoplay="autoplay"></video>';
  109. }
  110. function updateStats() {
  111. var text = '847正在为您P2P加速' + (_totalP2PDownloaded/1024).toFixed(2)
  112. + 'MB 连接节点' + _peerNum + '个';
  113. document.getElementById('stats').innerText = text ;
  114. }
  115. </script>
  116. </body>
  117. </html>

参考:dplayer文档:http://dplayer.js.org/

转载请注明出处:文思齐远博客,如果对您有帮助,请帮忙点一下右侧的广告,谢谢您了!
支付宝打赏 微信打赏

我要评论

猜你想搜

实时天气

©2020 i847.cn
部分内容转自网络,如有损害您的权益,致邮联系:jiang2008wen#126.com,一经证实,立即删除!    我要留言
备案号:蜀ICP备18020563号-1