mirror of
https://github.com/LucasVbr/own-workspace.git
synced 2026-05-13 17:21:58 +00:00
✨#8 - Play / Pause and Mute / Unmute buttons
This commit is contained in:
@@ -2,8 +2,11 @@
|
|||||||
<div id="ytb-container">
|
<div id="ytb-container">
|
||||||
<div class="ytb" v-show="displayYoutube" id="player"></div>
|
<div class="ytb" v-show="displayYoutube" id="player"></div>
|
||||||
<div class="params">
|
<div class="params">
|
||||||
<button @click="prevPlaylist" >⏮</button>
|
<button @click="prevPlaylist">⏮</button>
|
||||||
|
<button @click="pausePlayPlaylist">⏯</button>
|
||||||
<button @click="nextPlaylist" @keydown.shift="easterEgg" id="next">⏭</button>
|
<button @click="nextPlaylist" @keydown.shift="easterEgg" id="next">⏭</button>
|
||||||
|
<button @click="setMuteState" v-if="!muted">🔇</button>
|
||||||
|
<button @click="setMuteState" v-else>🔊</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -26,35 +29,50 @@ export default {
|
|||||||
displayYoutube: true,
|
displayYoutube: true,
|
||||||
livesId: [],
|
livesId: [],
|
||||||
easterEggs: [],
|
easterEggs: [],
|
||||||
easterEggsSongsId:-1,
|
easterEggsSongsId: -1,
|
||||||
songId: 0
|
songId: 0,
|
||||||
|
muted: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
readFileAndStore()
|
readFileAndStore() {
|
||||||
{
|
|
||||||
let lofi = require("../data/lofi.json");
|
let lofi = require("../data/lofi.json");
|
||||||
this.livesId = lofi.id;
|
this.livesId = lofi.id;
|
||||||
this.easterEggs = lofi.easterEggs;
|
this.easterEggs = lofi.easterEggs;
|
||||||
},
|
},
|
||||||
nextPlaylist()
|
nextPlaylist() {
|
||||||
{
|
|
||||||
this.songId++ === this.livesId.length - 1 ? this.songId = 0 : this.songId;
|
this.songId++ === this.livesId.length - 1 ? this.songId = 0 : this.songId;
|
||||||
let id = this.livesId[this.songId];
|
let id = this.livesId[this.songId];
|
||||||
this.changeYtbSrc(id)
|
this.loadVideoFromApi(id)
|
||||||
},
|
},
|
||||||
prevPlaylist()
|
prevPlaylist() {
|
||||||
{
|
--this.songId === -1 ? this.songId = this.livesId.length - 1 : this.songId;
|
||||||
--this.songId === -1 ? this.songId = this.livesId.length - 1: this.songId;
|
|
||||||
let id = this.livesId[this.songId];
|
let id = this.livesId[this.songId];
|
||||||
this.changeYtbSrc(id)
|
this.loadVideoFromApi(id)
|
||||||
|
},
|
||||||
|
pausePlayPlaylist() {
|
||||||
|
if (player.getPlayerState() === 1) {
|
||||||
|
player.pauseVideo();
|
||||||
|
} else {
|
||||||
|
player.playVideo();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
easterEgg() {
|
easterEgg() {
|
||||||
this.easterEggsSongsId++ === this.easterEggs.length - 1 ? this.easterEggsSongsId = 0 : this.easterEggsSongsId;
|
this.easterEggsSongsId++ === this.easterEggs.length - 1 ? this.easterEggsSongsId = 0 : this.easterEggsSongsId;
|
||||||
let id = this.easterEggs[this.easterEggsSongsId];
|
let id = this.easterEggs[this.easterEggsSongsId];
|
||||||
this.changeYtbSrc(id)
|
this.loadVideoFromApi(id)
|
||||||
},
|
},
|
||||||
changeYtbSrc(id) {
|
setMuteState() {
|
||||||
|
if (this.muted) {
|
||||||
|
player.unMute();
|
||||||
|
player.setVolume(15);
|
||||||
|
} else {
|
||||||
|
player.mute();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.muted = !this.muted;
|
||||||
|
},
|
||||||
|
loadVideoFromApi(id) {
|
||||||
player.loadVideoById(id);
|
player.loadVideoById(id);
|
||||||
},
|
},
|
||||||
loadApi() {
|
loadApi() {
|
||||||
@@ -64,13 +82,16 @@ export default {
|
|||||||
videoId: "XDh0JcxrbPM",
|
videoId: "XDh0JcxrbPM",
|
||||||
playerVars: {
|
playerVars: {
|
||||||
'autoplay': 1,
|
'autoplay': 1,
|
||||||
'mute': 1
|
'mute': 1,
|
||||||
|
'rel': 0,
|
||||||
|
'showInfo': 0
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
onStateChange: window.onPlayerStateChange
|
onStateChange: window.onPlayerStateChange
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.getElementById("player").style.width = "100%";
|
let player_id = document.getElementById("player")
|
||||||
|
player_id.style.width = "100%";
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onPlayerStateChange = (event) => {
|
window.onPlayerStateChange = (event) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user