eventbus + player
This commit is contained in:
parent
e21efec752
commit
1f8db57354
5 changed files with 44 additions and 14 deletions
|
@ -30,6 +30,7 @@
|
||||||
"skeleton-elements": "^4.0.1",
|
"skeleton-elements": "^4.0.1",
|
||||||
"swiper": "^8.4.6",
|
"swiper": "^8.4.6",
|
||||||
"tailwindcss": "^3.2.4",
|
"tailwindcss": "^3.2.4",
|
||||||
|
"tiny-emitter": "^2.1.0",
|
||||||
"vue": "^3.2.45"
|
"vue": "^3.2.45"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import eventBus from '../js/eventBus'
|
||||||
|
|
||||||
import { Howl } from 'howler'
|
import { Howl } from 'howler'
|
||||||
import Button from './Button.vue'
|
import Button from './Button.vue'
|
||||||
|
|
||||||
|
@ -35,24 +37,35 @@ export default {
|
||||||
player: null
|
player: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// destroyed () {
|
destroyed () {
|
||||||
// this.$nuxt.$off('play:podcast', this.stop)
|
eventBus.$off('play:now')
|
||||||
// },
|
},
|
||||||
// mounted () {
|
mounted () {
|
||||||
// this.$nuxt.$on('play:podcast', this.stop)
|
const t = this
|
||||||
// },
|
eventBus.$on('play:now', function (url) {
|
||||||
|
t.play(url)
|
||||||
|
})
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
play () {
|
play (url) {
|
||||||
const rnd = Math.random()
|
var urls;
|
||||||
|
if (url === undefined) {
|
||||||
|
const rnd = Math.random()
|
||||||
|
urls = [
|
||||||
|
'https://stream.radioblackout.org/blackout.ogg?rnd=' + rnd,
|
||||||
|
'https://stream.radioblackout.org/blackout.mp3'
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
urls = [url]
|
||||||
|
}
|
||||||
this.player = new Howl({
|
this.player = new Howl({
|
||||||
autoSuspend: false,
|
autoSuspend: false,
|
||||||
html5: true,
|
html5: true,
|
||||||
preload: true,
|
preload: true,
|
||||||
src: ['https://stream.radioblackout.org/blackout.ogg?rnd=' + rnd,
|
src: urls,
|
||||||
'https://stream.radioblackout.org/blackout.mp3'],
|
})
|
||||||
})
|
console.log(this.player)
|
||||||
this.player.play()
|
this.player.play()
|
||||||
this.$nuxt.$emit('play:player')
|
|
||||||
},
|
},
|
||||||
stop () {
|
stop () {
|
||||||
if (this.player) {
|
if (this.player) {
|
||||||
|
|
9
src/js/eventBus.js
Normal file
9
src/js/eventBus.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// see https://v3-migration.vuejs.org/breaking-changes/events-api.html#_3-x-update
|
||||||
|
import emitter from 'tiny-emitter/instance'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
$on: (...args) => emitter.on(...args),
|
||||||
|
$once: (...args) => emitter.once(...args),
|
||||||
|
$off: (...args) => emitter.off(...args),
|
||||||
|
$emit: (...args) => emitter.emit(...args)
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ export default {
|
||||||
this.radioId = this.f7route.params.radioName
|
this.radioId = this.f7route.params.radioName
|
||||||
try {
|
try {
|
||||||
this.Radio = await radiomanifest.get(this.f7route.params.radioName)
|
this.Radio = await radiomanifest.get(this.f7route.params.radioName)
|
||||||
// console.log('got', this.Radio)
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('le cose non vanno mai sempre bene!', e)
|
console.error('le cose non vanno mai sempre bene!', e)
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
|
|
||||||
<f7-preloader v-if='loading' />
|
<f7-preloader v-if='loading' />
|
||||||
<f7-list v-else>
|
<f7-list v-else>
|
||||||
<f7-list-item v-for='episode in Show.episodes' :key='episode.url' :title='episode.title' :link='`/radio/${radioId}/shows/${Show.name}/${episode.url}`' :footer='episode.text' />
|
<a @click="play(episode)" v-for='episode in Show.episodes' :key='episode.url' >
|
||||||
|
<f7-list-item :title='episode.title' :footer='episode.text' />
|
||||||
|
</a>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
|
|
||||||
</f7-page>
|
</f7-page>
|
||||||
|
@ -18,6 +20,7 @@
|
||||||
<script>
|
<script>
|
||||||
import radiomanifest from '../js/radiomanifest'
|
import radiomanifest from '../js/radiomanifest'
|
||||||
import getPodcast from '../js/podcast'
|
import getPodcast from '../js/podcast'
|
||||||
|
import eventBus from '../js/eventBus'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'radio',
|
name: 'radio',
|
||||||
|
@ -46,6 +49,11 @@ export default {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('le cose non vanno mai sempre bene!', e)
|
console.error('le cose non vanno mai sempre bene!', e)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
play: function(episode) {
|
||||||
|
eventBus.$emit('play:now', episode.enclosure.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue