mirror of
https://github.com/LucasVbr/own-workspace.git
synced 2026-05-19 10:53:19 +00:00
✨#8 - Add Youtube API
This commit is contained in:
@@ -1,11 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="ytb-container">
|
<div id="ytb-container">
|
||||||
<div class="ytb" v-show="displayYoutube">
|
<div class="ytb" v-show="displayYoutube" id="player"></div>
|
||||||
<iframe width="100%" height="360" src="https://www.youtube-nocookie.com/embed/XDh0JcxrbPM?autoplay=1&mute=1" title="YouTube video player" frameborder="0"
|
|
||||||
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
|
|
||||||
id="youtube_video">
|
|
||||||
</iframe>
|
|
||||||
</div>
|
|
||||||
<div class="params">
|
<div class="params">
|
||||||
<button @click="prevPlaylist" >⏮</button>
|
<button @click="prevPlaylist" >⏮</button>
|
||||||
<button @click="nextPlaylist" @keydown.shift="easterEgg" id="next">⏭</button>
|
<button @click="nextPlaylist" @keydown.shift="easterEgg" id="next">⏭</button>
|
||||||
@@ -14,6 +9,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
function setupYtbApi() {
|
||||||
|
const tag = document.createElement("script");
|
||||||
|
tag.id = "iframe-demo";
|
||||||
|
tag.src = "https://www.youtube.com/iframe_api";
|
||||||
|
const [firstScriptTag] = document.getElementsByTagName("script");
|
||||||
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
let player;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "YtbPlayer",
|
name: "YtbPlayer",
|
||||||
@@ -51,12 +55,36 @@ export default {
|
|||||||
this.changeYtbSrc(id)
|
this.changeYtbSrc(id)
|
||||||
},
|
},
|
||||||
changeYtbSrc(id) {
|
changeYtbSrc(id) {
|
||||||
let ytb = document.getElementById("youtube_video")
|
player.loadVideoById(id);
|
||||||
ytb.src = "https://www.youtube.com/embed/" + id + "?autoplay=1";
|
},
|
||||||
|
loadApi() {
|
||||||
|
window.onYouTubeIframeAPIReady = () => {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
player = new window.YT.Player("player", {
|
||||||
|
videoId: "XDh0JcxrbPM",
|
||||||
|
playerVars: {
|
||||||
|
'autoplay': 1,
|
||||||
|
'mute': 1
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
onStateChange: window.onPlayerStateChange
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.getElementById("player").style.width = "100%";
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onPlayerStateChange = (event) => {
|
||||||
|
if (event.data === 0) {
|
||||||
|
this.nextPlaylist()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.readFileAndStore();
|
this.readFileAndStore();
|
||||||
|
setupYtbApi();
|
||||||
|
this.loadApi();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"7NOSDKb0HlU",
|
"7NOSDKb0HlU",
|
||||||
"-5KAN9_CzSA",
|
"-5KAN9_CzSA",
|
||||||
"jfKfPfyJRdk",
|
"jfKfPfyJRdk",
|
||||||
|
|
||||||
"GDQnA1LVCWA",
|
"GDQnA1LVCWA",
|
||||||
"-pzxY5DtZIQ",
|
"-pzxY5DtZIQ",
|
||||||
"Mu3BfD6wmPg",
|
"Mu3BfD6wmPg",
|
||||||
|
|||||||
Reference in New Issue
Block a user