From 88413ec2bedf048751785197d4f158a2e65486b0 Mon Sep 17 00:00:00 2001 From: Jorge Marcos Date: Fri, 4 Feb 2022 12:45:48 +0100 Subject: [PATCH] use radio buttons for freesound result selection, ensure audio seeking works in chrome --- .../onsets/src/components/FreesoundResult.vue | 32 ++++++++----------- .../src/components/FreesoundResultList.vue | 28 ++++++++++++---- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/examples/demos/onsets/src/components/FreesoundResult.vue b/examples/demos/onsets/src/components/FreesoundResult.vue index c4e9fa1..29a4326 100644 --- a/examples/demos/onsets/src/components/FreesoundResult.vue +++ b/examples/demos/onsets/src/components/FreesoundResult.vue @@ -13,11 +13,11 @@
+ v-model="playbackPosition" size="sm" step="any" @change="handleSeek" @input="handleSeek">
- + @@ -28,12 +28,11 @@ export default { emits: ['selected'], props: { soundResource: Object, - checked: Number }, data () { return { playing: false, - selected: false, + selected: -1, audio: null, seekMax: 100, playbackPosition: 0 @@ -41,7 +40,7 @@ export default { }, watch: { selected (isSelected) { - if (isSelected) this.$emit('selected'); + if (isSelected == this.soundResource.id) this.$emit('selected'); }, soundResource () { if (this.audio) { @@ -50,11 +49,6 @@ export default { this.playbackPosition = 0; } this.setupAudioElement(); - }, - checked (id) { - if (id != this.soundResource.id) { - this.selected = false; - } } }, created () { @@ -62,18 +56,11 @@ export default { }, methods: { handlePlay () { - const whilePlaying = () => { - this.playbackPosition = this.audio.currentTime; - this.rAF = requestAnimationFrame(whilePlaying) - }; - if (this.playing) { this.stopAudio(); return; } - this.audio.play(); - requestAnimationFrame(whilePlaying); - this.playing = true; + this.playAudio(); }, setupAudioElement () { this.audio = document.createElement('audio'); @@ -91,10 +78,19 @@ export default { handleSeek (pos) { this.audio.currentTime = Number(pos); }, + playAudio () { + this.audio.play(); + requestAnimationFrame(this.whilePlaying.bind(this)); + this.playing = true; + }, stopAudio () { this.audio.pause(); cancelAnimationFrame(this.rAF) this.playing = false; + }, + whilePlaying () { + this.playbackPosition = this.audio.currentTime; + this.rAF = requestAnimationFrame(this.whilePlaying.bind(this)) } } } diff --git a/examples/demos/onsets/src/components/FreesoundResultList.vue b/examples/demos/onsets/src/components/FreesoundResultList.vue index e024d72..ba96fd5 100644 --- a/examples/demos/onsets/src/components/FreesoundResultList.vue +++ b/examples/demos/onsets/src/components/FreesoundResultList.vue @@ -1,11 +1,16 @@