Added loader and stuff

This commit is contained in:
Pünkösd Marcell 2021-06-14 01:55:43 +02:00
parent fd8d7a9ec6
commit b7b00db726
1 changed files with 25 additions and 11 deletions

View File

@ -1,7 +1,9 @@
<template> <template>
<b-container fluid style="height: 100vh"> <b-container fluid style="height: 100vh">
<b-row v-if="errorCondition"> <b-row v-if="errorText || soundsLoaded < totalSounds">
{{ errorCondition }} <b>{{ errorText }}</b>
<br>
Loaded {{ soundsLoaded }} of {{ totalSounds }} sound files...
</b-row> </b-row>
<b-row v-else class="mb-2 h-100"> <b-row v-else class="mb-2 h-100">
<b-col v-for="(snd,id) in availableSounds" :key="id" class="my-2" :cols="columnWidth" align-v="stretch"> <b-col v-for="(snd,id) in availableSounds" :key="id" class="my-2" :cols="columnWidth" align-v="stretch">
@ -24,9 +26,15 @@ export default {
return { return {
nowPlaying: -1, nowPlaying: -1,
availableSounds: [], availableSounds: [],
columnWidth: 6, bgSound: null,
errorCondition: false, soundsLoaded: 0,
bgSound: null errorText: null,
columnWidth: 6
}
},
computed: {
totalSounds() {
return this.availableSounds.length + 1 // because bg
} }
}, },
methods: { methods: {
@ -42,9 +50,9 @@ export default {
} else { } else {
this.bgSound.pause() // the background sound must be paused this.bgSound.pause() // the background sound must be paused
this.availableSounds.forEach((snd) => { // Stop all other effects if (this.nowPlaying !== -1) {
snd.howl.stop() this.availableSounds[this.nowPlaying].howl.stop()
}) }
sample.play() sample.play()
this.nowPlaying = sampleId this.nowPlaying = sampleId
@ -57,7 +65,10 @@ export default {
this.columnWidth = response.data['columnWidth'] || 6 this.columnWidth = response.data['columnWidth'] || 6
this.bgSound = new Howl({ this.bgSound = new Howl({
src: response.data['bg'], src: response.data['bg'],
loop: true loop: true,
onload: () => this.soundsLoaded++,
preload: true,
onloaderror: (id, err) => this.errorText = id + err
}) })
response.data['availableSounds'].forEach((sndData) => { response.data['availableSounds'].forEach((sndData) => {
@ -69,12 +80,15 @@ export default {
onend: () => { onend: () => {
this.nowPlaying = -1 this.nowPlaying = -1
this.bgSound.play() // Continue background sound this.bgSound.play() // Continue background sound
} },
onload: () => this.soundsLoaded++,
preload: true,
onloaderror: (id, err) => this.errorText = `${id} ${err}`
}) })
}) })
}) })
}).catch((err) => this.errorCondition = err) }).catch((err) => this.errorText = err)
} }
} }
</script> </script>