player: propagate metadata

This commit is contained in:
boyska 2023-03-19 11:56:02 +00:00
parent a412cfc7ca
commit d88b9bdd87
3 changed files with 22 additions and 12 deletions

View file

@ -1,6 +1,9 @@
<template> <template>
<f7-link @click="onPlay" v-if="status != 'playing'">Play</f7-link> <f7-toolbar v-if="status != 'empty'">
<f7-link @click="onPause" v-else>Pause</f7-link> <f7-link @click="onPlay" v-if="status == 'pause'">Play</f7-link>
<f7-link @click="onPause" v-if="status == 'playing'">Pause</f7-link>
{{title}}
</f7-toolbar>
</template> </template>
<script> <script>
@ -13,7 +16,7 @@ export default {
data () { data () {
return { return {
loading: true, loading: true,
status: 'pause', status: 'empty',
volume: 100, volume: 100,
title: 'RadioBlackout > DIRETTA', title: 'RadioBlackout > DIRETTA',
subtitle: '', subtitle: '',
@ -25,20 +28,22 @@ export default {
eventBus.$off('play:now') eventBus.$off('play:now')
}, },
mounted () { mounted () {
// XXX: should track events from this.player, instead of manually setting
const t = this const t = this
eventBus.$on('play:now', function (url) { eventBus.$on('play:now', function (url, metadata) {
t.play(url) t.play(url, metadata)
t.status = 'playing' t.status = 'playing'
}) })
eventBus.$on('play:pause', function() { eventBus.$on('play:pause', function() {
if(t.player) { if(t.player) {
t.player.pause() t.player.pause()
t.status = 'pause'
} }
t.status = 'pause'
}) })
eventBus.$on('play:resume', function() { eventBus.$on('play:resume', function() {
if(t.player) { if(t.player) {
t.player.play() t.player.play()
t.status = 'playing'
} }
}) })
}, },
@ -49,7 +54,7 @@ export default {
onPause() { onPause() {
eventBus.$emit('play:pause') eventBus.$emit('play:pause')
}, },
play (url) { play (url, metadata) {
let newPlayer = new Howl({ let newPlayer = new Howl({
autoSuspend: false, autoSuspend: false,
html5: true, html5: true,
@ -61,6 +66,11 @@ export default {
this.player.stop() this.player.stop()
} }
this.player = newPlayer this.player = newPlayer
if(metadata !== undefined) {
this.title = metadata.title
this.live = metadata.live
}
}, },
stop () { stop () {
if (this.player) { if (this.player) {

View file

@ -27,14 +27,11 @@
<template> <template>
<f7-app v-bind="f7params" > <f7-app v-bind="f7params" >
<!-- Top Navbar --> <!-- Top Navbar -->
<f7-toolbar>
<Player />
</f7-toolbar>
<f7-navbar back-link="Back" title='plaid' /> <f7-navbar back-link="Back" title='plaid' />
<Player />
<!-- Your main view, should have "view-main" class --> <!-- Your main view, should have "view-main" class -->
<f7-view main url="/"></f7-view> <f7-view main url="/"></f7-view>
</f7-app> </f7-app>
</template> </template>

View file

@ -52,7 +52,10 @@ export default {
}, },
methods: { methods: {
play: function(episode) { play: function(episode) {
eventBus.$emit('play:now', episode.enclosure.url) eventBus.$emit('play:now', episode.enclosure.url, {
live: false,
title: episode.title
})
} }
} }
} }