forked from LonelyCpp/react-native-youtube-iframe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iframe.html
151 lines (135 loc) · 4.18 KB
/
iframe.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width," />
<style>
body {
margin: 0;
}
.container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
}
.video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 95%;
}
</style>
</head>
<body>
<div class="container">
<div class="video" id="player"></div>
</div>
<script>
const randomPlayerId = 'player' + Date.now();
document.getElementById('player').id = randomPlayerId;
const parsedUrl = new URL(window.location.href);
const UrlQueryData = parsedUrl.searchParams.get('data');
const {
end,
list,
color,
start,
rel_s,
loop_s,
listType,
playerLang,
playlist,
videoId_s,
controls_s,
cc_lang_pref_s,
contentScale_s,
allowWebViewZoom,
modestbranding_s,
iv_load_policy,
preventFullScreen_s,
showClosedCaptions_s,
} = JSON.parse(UrlQueryData);
function sendMessageToRN(msg) {
window.ReactNativeWebView.postMessage(JSON.stringify(msg));
}
let metaString = '';
if (contentScale_s) {
metaString += `initial-scale=${contentScale_s}, `;
}
if (!allowWebViewZoom) {
metaString += `maximum-scale=${contentScale_s}`;
}
const viewport = document.querySelector('meta[name=viewport]');
viewport.setAttribute('content', 'width=device-width, ' + metaString);
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player(randomPlayerId, {
width: '1000',
height: '1000',
videoId: videoId_s,
playerVars: {
end: end,
rel: rel_s,
list: list,
color: color,
loop: loop_s,
start: start,
playsinline: 1,
hl: playerLang,
playlist: playlist,
listType: listType,
controls: controls_s,
fs: preventFullScreen_s,
cc_lang_pref: cc_lang_pref_s,
iv_load_policy: iv_load_policy,
modestbranding: modestbranding_s,
cc_load_policy: showClosedCaptions_s,
},
events: {
onReady: onPlayerReady,
onError: onPlayerError,
onStateChange: onPlayerStateChange,
onPlaybackRateChange: onPlaybackRateChange,
onPlaybackQualityChange: onPlaybackQualityChange,
},
});
}
function onPlayerError(event) {
sendMessageToRN({eventType: 'playerError', data: event.data});
}
function onPlaybackRateChange(event) {
sendMessageToRN({eventType: 'playbackRateChange', data: event.data});
}
function onPlaybackQualityChange(event) {
sendMessageToRN({eventType: 'playerQualityChange', data: event.data});
}
function onPlayerReady(event) {
sendMessageToRN({eventType: 'playerReady'});
}
function onPlayerStateChange(event) {
sendMessageToRN({eventType: 'playerStateChange', data: event.data});
}
var isFullScreen = false;
function onFullScreenChange() {
isFullScreen =
document.fullscreenElement ||
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement;
sendMessageToRN({
eventType: 'fullScreenChange',
data: Boolean(isFullScreen),
});
}
document.addEventListener('fullscreenchange', onFullScreenChange);
document.addEventListener('msfullscreenchange', onFullScreenChange);
document.addEventListener('mozfullscreenchange', onFullScreenChange);
document.addEventListener('webkitfullscreenchange', onFullScreenChange);
</script>
</body>
</html>