change volume with slider

This commit is contained in:
Jonas Heinrich 2020-10-21 11:26:41 +02:00
parent 94064c574c
commit efaeca5477
3 changed files with 38 additions and 7 deletions

View File

@ -1,6 +1,7 @@
<template> <template>
<Content app-name="radio"> <Content app-name="radio">
<Navigation /> <Navigation
@changeVolume="changeVolume" />
<AppContent> <AppContent>
<Breadcrumbs class="breadcrumbs"> <Breadcrumbs class="breadcrumbs">
<Breadcrumb title="Home" href="/" /> <Breadcrumb title="Home" href="/" />
@ -102,8 +103,8 @@ export default {
*/ */
doPlay(station) { doPlay(station) {
if (audioPlayer !== null) { if (audioPlayer !== null) {
audioPlayer.fade(100, 0, 500) // FIXME persistent volume state audioPlayer.fade(1, 0, 500) // FIXME persistent volume state
audioPlayer.unload() // FIXME do unload after fadeout // FIXME fade out
} }
this.$jquery.get('http://de1.api.radio-browser.info/json/url/' + station.stationuuid, this.$jquery.get('http://de1.api.radio-browser.info/json/url/' + station.stationuuid,
{ {
@ -112,9 +113,14 @@ export default {
audioPlayer = new Howl({ audioPlayer = new Howl({
src: [station.url_resolved], src: [station.url_resolved],
volume: 0, volume: 0,
onfade() {
if (this.volume() === 0) {
this.unload()
}
},
}) })
audioPlayer.play() audioPlayer.play()
audioPlayer.fade(0, 100, 500) // FIXME persistent volume state audioPlayer.fade(0.1, 1, 500) // FIXME persistent volume state
const stationMetadata = document.getElementById('stationMetadata') const stationMetadata = document.getElementById('stationMetadata')
stationMetadata.textContent = station.name stationMetadata.textContent = station.name
@ -138,11 +144,13 @@ export default {
}) })
.done(function(data) { .done(function(data) {
vm.loading = false vm.loading = false
console.log(vm.loading)
vm.tableData = vm.tableData.concat(data) vm.tableData = vm.tableData.concat(data)
vm.offset += 20 vm.offset += 20
}) })
}, },
/**
* On scroll event, load more stations if bottom reached
*/
scroll() { scroll() {
window.onscroll = () => { window.onscroll = () => {
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
@ -150,6 +158,11 @@ export default {
} }
} }
}, },
changeVolume(volume) {
if (audioPlayer !== null) {
audioPlayer.volume(volume)
}
},
}, },
} }
</script> </script>

View File

@ -19,7 +19,9 @@
:title="t('radio', 'Categories')" /> :title="t('radio', 'Categories')" />
</template> </template>
<template #footer> <template #footer>
<Player :pinned="true" /> <Player
:pinned="true"
@changeVolume="changeVolume" />
</template> </template>
</AppNavigation> </AppNavigation>
</template> </template>
@ -36,6 +38,11 @@ export default {
AppNavigationItem, AppNavigationItem,
Player, Player,
}, },
methods: {
changeVolume(volume) {
this.$emit('changeVolume', volume)
},
},
} }
</script> </script>

View File

@ -3,11 +3,14 @@
<button id="playbutton" class="play" :style="playerIcon" /> <button id="playbutton" class="play" :style="playerIcon" />
<div id="volumeicon" class="full" /> <div id="volumeicon" class="full" />
<input <input
v-model="sliderVal"
class="volume" class="volume"
type="range" type="range"
name="volume" name="volume"
min="0" min="0"
max="50"> max="1"
step=".05"
@input="changeVolume">
<span id="stationMetadata" /> <span id="stationMetadata" />
</div> </div>
</template> </template>
@ -21,6 +24,11 @@ export default {
}, },
} }
}, },
methods: {
changeVolume() {
this.$emit('changeVolume', this.sliderVal)
},
},
} }
</script> </script>
@ -71,14 +79,17 @@ export default {
} }
#volumeicon.full { #volumeicon.full {
background: red;
/* background-image: url('../img/sound_full.png'); */ /* background-image: url('../img/sound_full.png'); */
} }
#volumeicon.mid { #volumeicon.mid {
background: yellow;
/* background-image: url('../img/sound_mid.png'); */ /* background-image: url('../img/sound_mid.png'); */
} }
#volumeicon.silent { #volumeicon.silent {
background: green;
/* background-image: url('../img/sound_silent.png'); */ /* background-image: url('../img/sound_silent.png'); */
} }