koel/resources/assets/js/components/main-wrapper/main-content/youtube-player.vue
2016-07-30 23:32:17 +08:00

67 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<section id="youTubePlayer">
<h1 class="heading"><span>YouTube Video</span></h1>
<div id="player">
<p class="none">Your YouTube video will be played here.<br/>
You can start a video playback from the right sidebar. When a song is playing, that is.<br>
It might also be worth noting that videos volume, progress and such are controlled from within
the video itself, and not via Koels controls.</p>
</div>
</section>
</template>
<script>
import { event } from '../../../utils';
import { playback } from '../../../services';
import YouTubePlayer from 'youtube-player';
let player;
export default {
name: 'main-wrapper--main-content--youtube-player',
methods: {
/**
* Initialize the YouTube player. This should only be called once.
*/
initPlayer() {
if (!player) {
player = YouTubePlayer('player', {
width: '100%',
height: '100%',
});
player.on('stateChange', event => {
// Pause song playback when video is played
event.data === 1 && playback.pause();
});
}
},
},
created() {
event.on({
'youtube:play': id => {
this.initPlayer();
player.loadVideoById(id);
player.playVideo();
},
/**
* Stop video playback when a song is played/resumed.
*/
'song:played': () => player && player.pauseVideo(),
});
},
};
</script>
<style lang="sass" scoped>
@import "../../../../sass/partials/_vars.scss";
@import "../../../../sass/partials/_mixins.scss";
.none {
color: $color2ndText;
padding: 16px 24px;
}
</style>