forked from PearInc/PearPlayer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player-test.html
112 lines (99 loc) · 5.6 KB
/
player-test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pear Player</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="main">
<!--<video id="pearvideo" controls>-->
<video id="pearvideo" src="https://qq.webrtc.win/tv/Pear-Demo-Yosemite_National_Park.mp4" controls>
<!--<video id="pearvideo" src="https://qq.webrtc.win/tv/Pear-Demo-Corporate-Video-V5.mp4" controls>-->
<!--<video id="pearvideo" src="https://qq.webrtc.win/tv/Pear-demo-your-name.mp4" controls>-->
<!--<video id="pearvideo" src="https://qq.webrtc.win/newifi/Pear-Demo-planet.earth.ii.s01e04.mp4" controls>-->
<!--<video id="pearvideo" src="https://qq.webrtc.win/tv/Pear-Demo-SoundOfMusic_172.mp4" controls>-->
</video>
</div>
<!--<script src="../dist/pear-player.js"></script>-->
<script src="../dist/pear-player.min.js"></script>
<script>
// console.log(encodeURI('http://localhost:6075/downloader/binary-file?src=https://qq.webrtc.win/binary/Pear-Demo-kodexplorer4.00.zip'))
//第一个参数为video标签的id或class
if (PearPlayer.isMSESupported()) {
var player = new PearPlayer('#pearvideo', {
// src: 'https://qq.webrtc.win/tv/Pear-Demo-Yosemite_National_Park.mp4',
scheduler: 'IdleFirst', //节点调度算法,默认IdleFirst,其它内置调度算法有“WebRTCFirst“和”CloudFirst”
autoplay: true, //是否自动播发视频,默认true
interval: 5000, //滑动窗口的时间间隔,单位毫秒,默认5s
useDataChannel: false, //是否开启data channel,默认true
dataChannels: 20, //创建data channel的最大数量,默认20
useTorrent: true, //是否开启Browser P2P(基于Webtorrent),默认true
// magnetURI: 'magnet:?xt=...', //可手动传入magnetURI,需先将useTorrent设为true
// trackers:["wss://tracker.openwebtorrent.com"], //可手动传入tracker服务器,需先将useTorrent设为true
sources: [], //指定下载源,增加这个字段后pearplayer不会再向后台请求节点,建议下载源多于5个以保证流畅播放
useMonitor: true, //是否开启monitor,会稍微影响性能,默认true
BTMode: false, //是否开启纯BT下载模式(基于webtorrent),默认false,
debug: true, //是否开启debug模式,开启后可以在console中查看log,默认false
algorithm: 'pull', //下载算法,有‘push’和‘pull’两种,默认‘pull’
geoEnabled: true //是否开启geo接口,默认false
});
player.on('fallback', onFallback); //播放器出现异常时的回调函数
player.on('begin', onBegin); //开始下载时触发
player.on('progress', onProgress); //回调目前的下载进度
player.on('cloudspeed', onCloudSpeed); //来自cloud节点的HTTP的瞬时下载速度
player.on('fogspeed', onFogSpeed); //来自fog的节点(包括HTTP和WebRTC)的瞬时下载速度
player.on('fograte', onWebRTCRate); //fog节点的下载比率(下载的字节数除以总的字节数)
player.on('buffersources', onBufferSources); //buffer map,记录每个buffer的下载源类型,其中s: server n: node d: data channel b: browser
player.on('done', onDone); //结束下载时触发
player.on('traffic', onTraffic); //节点流量统计,每次下载buffer都会触发该事件
player.on('sourcemap', onSourceMap); //记录每个buffer的下载源类型,其中s: server n: node d: data channel b: browser
player.on('metadata', onMetaData);
player.on('canplay', onCanPlay);
} else {
fallback()
}
function onBegin(fileLength, chunks) {
console.log('start downloading buffer by first aid, file length is:' + fileLength/1024/1024 + ' total chunks:' + chunks);
}
function onProgress(downloaded) {
console.log('Progress: ' + (downloaded * 100).toFixed(1) + '%');
}
function onCloudSpeed(speed) {
console.log('Cloud download speed: ' + speed + 'KBps');
}
function onFogSpeed(speed) {
console.log('Fog download speed: ' + speed + 'KBps');
}
function onWebRTCRate(p2pRate) {
console.log('Fog Ratio: ' + (p2pRate * 100).toFixed(1) + '%');
}
function onDone() {
console.log('finished downloading buffer by first aid');
}
function onFallback() {
fallback();
}
function onBufferSources(bufferSources) { //s: server n: node d: data channel b: browser
console.log('Current Buffer Sources:' + bufferSources);
console.log(JSON.stringify(player.debugInfo));
}
function onTraffic(mac, size, type) {
console.log('type:'+type+' mac:'+mac+' downloaded:'+size/1024/1024+'MB');
}
function onSourceMap(sourceType, index) {
console.log('Received source type:' + sourceType + ' index:' + index);
}
function onMetaData(metadata) {
console.log('metadata bitrate:'+Math.round(metadata.bitrate/1024)+' KB/s');
}
function onCanPlay(delay) {
console.log('canplay delay:' + delay);
}
function fallback() {
var video = document.getElementById('pearvideo');
video.play()
}
</script>
</body>
</html>