1 Star 1 Fork 1

swarmcloud/hls-p2p-engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
plyr.html 2.62 KB
一键复制 编辑 原始数据 按行查看 历史
snowinszu 提交于 2024-07-08 13:25 . release v2.11.5
<!DOCTYPE html>
<html lang="en">
<div class="container">
<video controls crossorigin playsinline></video>
</div>
<p id="version"></p>
<h3>download info:</h3>
<p id="info"></p>
<link rel="stylesheet" href="//cdn.plyr.io/3.4.7/plyr.css">
<script src="//cdn.plyr.io/3.4.7/plyr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@swarmcloud/hls/hls.min.js"></script>
<script>
var p2pConfig = {
logLevel: 'debug',
live: false, // set to true in live mode
swFile: './sw.js',
getStats: function (totalP2PDownloaded, totalP2PUploaded, totalHTTPDownloaded) {
var total = totalHTTPDownloaded + totalP2PDownloaded;
document.querySelector('#info').innerText = `p2p ratio: ${Math.round(totalP2PDownloaded/total*100)}%, saved traffic: ${totalP2PDownloaded}KB, uploaded: ${totalP2PUploaded}KB`;
},
// trackerZone: 'hk', // if using Hongkong tracker
// trackerZone: 'us', // if using USA tracker
// token: YOUR_TOKEN
// Other p2pConfig options provided by CDNBye
}
document.querySelector('#version').innerText = `hls.js version: ${Hls.version} cdnbye version: ${Hls.engineVersion}`;
if (!Hls.P2pEngine.isMSESupported()) {
// use ServiceWorker based p2p engine if hls.js is not supported, need additional file sw.js
new Hls.P2pEngine.ServiceWorkerEngine(p2pConfig)
}
Hls.P2pEngine.tryRegisterServiceWorker(p2pConfig).then(() => {
var source = 'https://test-streams.mux.dev/x36xhzz/url_2/193039199_mp4_h264_aac_ld_7.m3u8';
var video = document.querySelector('video');
// For more options see: https://github.com/sampotts/plyr/#options
// captions.update is required for captions to work with hls.js
var player = new Plyr(video, {
captions: {active: true, update: true, language: 'en'},
// autoplay: true,
});
if (!Hls.isSupported()) {
video.src = source;
} else {
// For more Hls.js options, see https://github.com/dailymotion/hls.js
var hls = new Hls({
p2pConfig
});
hls.loadSource(source);
hls.attachMedia(video);
window.hls = hls;
// Handle changing captions
player.on('languagechange', () => {
// Caption support is still flaky. See: https://github.com/sampotts/plyr/issues/994
setTimeout(() => hls.subtitleTrack = player.currentTrack, 50);
});
}
// Expose player so it can be used from the console
window.player = player;
})
</script>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/swarmcloud/hls-p2p-engine.git
git@gitee.com:swarmcloud/hls-p2p-engine.git
swarmcloud
hls-p2p-engine
hls-p2p-engine
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385