-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.html
85 lines (74 loc) · 2.28 KB
/
player.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
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
padding: 0;
background: black;
}
</style>
</head>
<body>
<div id="player"></div>
<script>
let tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
let firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
let player;
let gameStarted;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: window. innerHeight,
width: window. innerWidth,
events: {
'onReady': onPlayerReady,
'onError': onPlayerError,
'onStateChange': onPlayerStateChange
},
playerVars: { 'controls': 0, 'disablekb': 1 }
});
}
function onPlayerReady(event) {
location.href = "uniwebview://state?value=READY";
}
function onPlayerError(event) {
location.href = "uniwebview://error?code=" + event.data;
}
function onPlayerStateChange(event) {
location.href = "uniwebview://playerState?value=" + event.data;
if (gameStarted) {
if (event.data == 2) {
location.href = "uniwebview://state?value=PAUSED";
}
} else {
if (event.data == 1) {
location.href = "uniwebview://state?value=BUFFERING";
} else if (event.data == 2) {
location.href = "uniwebview://state?value=LOADED";
}
}
}
function loadById(id){
player.loadVideoById(id);
gameStarted = false;
}
function play(){
player.playVideo();
if (!gameStarted) gameStarted = true;
}
function pause(){
player.pauseVideo();
}
function restart(){
gameStarted = false;
player.seekTo(0);
pause();
}
function mute(){
player.isMuted() ? player.unMute(): player.mute();
}
</script>
</body>
</html>