work on player

This commit is contained in:
bkfox
2019-08-15 12:43:10 +02:00
parent e0f1ac498f
commit abaccf9ded
35 changed files with 17936 additions and 185 deletions

View File

@ -1,11 +1,9 @@
import Vue from 'vue';
import OnAir from './onAir.vue';
import Player from './player.vue';
import Tab from './tab.vue';
import Tabs from './tabs.vue';
Vue.component('a-on-air', OnAir);
Vue.component('a-player', Player);
Vue.component('a-tab', Tab);
Vue.component('a-tabs', Tabs);

View File

@ -1,63 +0,0 @@
<template>
<div class="media">
<!-- TODO HERE -->
</div>
</template>
<script>
export default {
props: {
url: String,
timeout: Number,
},
data() {
return {
// promise is set to null on destroy: this is used as check
// for timeout to know wether to repeat itself or not.
promise: null,
// on air infos
on_air: null
}
},
methods: {
fetch() {
const promise = fetch(url).then(response =>
reponse.ok ? response.json
: Promise.reject(response)
).then(data => {
this.on_air = data.results;
return this.on_air
})
this.promise = promise;
return promise;
},
refresh() {
const promise = this.fetch();
promise.then(data => {
if(promise != this.promise)
return;
window.setTimeout(() => this.update(), this.timeout*1000)
})
},
},
mounted() {
this.update()
},
destroyed() {
this.promise = null;
}
}
</script>

View File

@ -1,7 +1,8 @@
<template>
<div class="media">
<div class="media-left">
<div class="button is-size-4" @click="toggle()">
<div class="button" @click="toggle()"
:title="buttonTitle" :aria-label="buttonTitle">
<span class="fas fa-pause" v-if="playing"></span>
<span class="fas fa-play" v-else></span>
</div>
@ -9,13 +10,24 @@
<slot name="sources"></slot>
</audio>
</div>
<div class="media-content">
<div class="media-left media-cover" v-if="onAir && onAir.cover">
<img :src="onAir.cover" class="cover" />
</div>
<div class="media-content" v-if="onAir && onAir.type == 'track'">
<slot name="track" :onAir="onAir" :liveInfo="liveInfo"></slot>
</div>
<div class="media-content" v-else-if="onAir && onAir.type == 'diffusion'">
<slot name="diffusion" :onAir="onAir" :liveInfo="liveInfo"></slot>
</div>
<div v-else><slot name="empty"></slot></div>
</div>
</div>
</template>
<script>
import LiveInfo from 'js/liveInfo';
export const State = {
paused: 0,
playing: 1,
@ -26,11 +38,14 @@ export default {
data() {
return {
state: State.paused,
liveInfo: new LiveInfo(this.liveInfoUrl, this.liveInfoTimeout),
}
},
props: {
onAir: String,
buttonTitle: String,
liveInfoUrl: String,
liveInfoTimeout: { type: Number, default: 5},
src: String,
},
@ -38,6 +53,16 @@ export default {
paused() { return this.state == State.paused; },
playing() { return this.state == State.playing; },
loading() { return this.state == State.loading; },
onAir() {
return this.liveInfo.items && this.liveInfo.items[0];
},
buttonStyle() {
if(!this.onAir)
return;
return { backgroundImage: `url(${this.onAir.cover})` }
}
},
methods: {
@ -71,8 +96,12 @@ export default {
},
mounted() {
this.load(this.src);
}
this.liveInfo.refresh()
},
destroyed() {
this.liveInfo.drop()
},
}
</script>