mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 11:42:05 +00:00
including youtube iframe api handled by the YouTubeVideo on demand
This commit is contained in:
parent
80cc9697f7
commit
7baa847972
2 changed files with 55 additions and 33 deletions
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script src="https://www.youtube.com/iframe_api"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -23,45 +23,21 @@ function YouTubeVideo(containerElement) {
|
||||||
var volumeChangedIntervalId = window.setInterval(onVolumeChangedInterval, 100);
|
var volumeChangedIntervalId = window.setInterval(onVolumeChangedInterval, 100);
|
||||||
var subtitles = new HTMLSubtitles(containerElement);
|
var subtitles = new HTMLSubtitles(containerElement);
|
||||||
var video = null;
|
var video = null;
|
||||||
// TODO handle script element
|
var scriptElement = document.createElement('script');
|
||||||
var stylesElement = document.createElement('style');
|
var stylesElement = document.createElement('style');
|
||||||
var videoContainer = document.createElement('div');
|
var videoContainer = document.createElement('div');
|
||||||
|
|
||||||
subtitles.addListener('error', onSubtitlesError);
|
scriptElement.type = 'text/javascript';
|
||||||
subtitles.addListener('load', updateSubtitleText);
|
scriptElement.src = 'https://www.youtube.com/iframe_api';
|
||||||
|
scriptElement.onload = onYouTubePlayerApiLoaded;
|
||||||
|
scriptElement.onerror = onYouTubePlayerApiError;
|
||||||
|
containerElement.appendChild(scriptElement);
|
||||||
containerElement.appendChild(stylesElement);
|
containerElement.appendChild(stylesElement);
|
||||||
stylesElement.sheet.insertRule('#' + containerElement.id + ' .video { position: absolute; width: 100%; height: 100%; z-index: -1; }', stylesElement.sheet.cssRules.length);
|
stylesElement.sheet.insertRule('#' + containerElement.id + ' .video { position: absolute; width: 100%; height: 100%; z-index: -1; }', stylesElement.sheet.cssRules.length);
|
||||||
containerElement.appendChild(videoContainer);
|
containerElement.appendChild(videoContainer);
|
||||||
videoContainer.classList.add('video');
|
videoContainer.classList.add('video');
|
||||||
|
subtitles.addListener('error', onSubtitlesError);
|
||||||
YT.ready(() => {
|
subtitles.addListener('load', updateSubtitleText);
|
||||||
if (destroyed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
video = new YT.Player(videoContainer, {
|
|
||||||
height: '100%',
|
|
||||||
width: '100%',
|
|
||||||
playerVars: {
|
|
||||||
autoplay: 1,
|
|
||||||
cc_load_policy: 3,
|
|
||||||
controls: 0,
|
|
||||||
disablekb: 1,
|
|
||||||
enablejsapi: 1,
|
|
||||||
fs: 0,
|
|
||||||
iv_load_policy: 3,
|
|
||||||
loop: 0,
|
|
||||||
modestbranding: 1,
|
|
||||||
playsinline: 1,
|
|
||||||
rel: 0
|
|
||||||
},
|
|
||||||
events: {
|
|
||||||
onError: onVideoError,
|
|
||||||
onReady: onVideoReady,
|
|
||||||
onStateChange: onVideoStateChange
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function getPaused() {
|
function getPaused() {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
|
|
@ -192,6 +168,52 @@ function YouTubeVideo(containerElement) {
|
||||||
critical: false
|
critical: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function onYouTubePlayerApiError() {
|
||||||
|
onError({
|
||||||
|
code: 12,
|
||||||
|
message: 'YouTube player API failed to load',
|
||||||
|
critical: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function onYouTubePlayerApiLoaded() {
|
||||||
|
if (destroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!YT) {
|
||||||
|
onYouTubePlayerApiError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YT.ready(() => {
|
||||||
|
if (destroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
video = new YT.Player(videoContainer, {
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
playerVars: {
|
||||||
|
autoplay: 1,
|
||||||
|
cc_load_policy: 3,
|
||||||
|
controls: 0,
|
||||||
|
disablekb: 1,
|
||||||
|
enablejsapi: 1,
|
||||||
|
fs: 0,
|
||||||
|
iv_load_policy: 3,
|
||||||
|
loop: 0,
|
||||||
|
modestbranding: 1,
|
||||||
|
playsinline: 1,
|
||||||
|
rel: 0
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
onError: onVideoError,
|
||||||
|
onReady: onVideoReady,
|
||||||
|
onStateChange: onVideoStateChange
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
function onVideoError(error) {
|
function onVideoError(error) {
|
||||||
var message;
|
var message;
|
||||||
switch (error.data) {
|
switch (error.data) {
|
||||||
|
|
@ -497,6 +519,7 @@ function YouTubeVideo(containerElement) {
|
||||||
clearInterval(durationChangedIntervalId);
|
clearInterval(durationChangedIntervalId);
|
||||||
clearInterval(volumeChangedIntervalId);
|
clearInterval(volumeChangedIntervalId);
|
||||||
video.destroy();
|
video.destroy();
|
||||||
|
containerElement.removeChild(scriptElement);
|
||||||
containerElement.removeChild(videoElement);
|
containerElement.removeChild(videoElement);
|
||||||
containerElement.removeChild(stylesElement);
|
containerElement.removeChild(stylesElement);
|
||||||
subtitles.dispatch('command', 'destroy');
|
subtitles.dispatch('command', 'destroy');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue