Emit an event every time an audio is recorded

* Use ; on code added to make it consistent with the rest of the file
pull/4734/head
Daniel Gayoso González 2 years ago
parent 4727a8ef7f
commit c51a4519c8
  1. 25
      assets/vue/components/AudioRecorder.vue

@ -75,7 +75,7 @@ const props = defineProps({
} }
}); });
const emit = defineEmits(["attach-audio"]); const emit = defineEmits(["attach-audio", "recorded-audio"]);
defineExpose({ defineExpose({
record, record,
@ -140,9 +140,10 @@ async function stop() {
const audioBlob = await recorder.getBlob(); const audioBlob = await recorder.getBlob();
recorderState.audioList.push(audioBlob); recorderState.audioList.push(audioBlob);
emit('recorded-audio', audioBlob);
recorderState.isRecording = false; recorderState.isRecording = false;
stopTimer() stopTimer();
} }
function attachAudio(audio) { function attachAudio(audio) {
@ -157,9 +158,9 @@ function attachAudio(audio) {
let timer = null; let timer = null;
function startTimer() { function startTimer() {
recorderState.seconds = 0 recorderState.seconds = 0;
recorderState.minutes = 0 recorderState.minutes = 0;
recorderState.hours = 0 recorderState.hours = 0;
timer = setInterval(() => { timer = setInterval(() => {
recorderState.seconds = recorderState.seconds + 1 recorderState.seconds = recorderState.seconds + 1
@ -171,19 +172,19 @@ function startTimer() {
recorderState.hours = recorderState.hours + 1 recorderState.hours = recorderState.hours + 1
recorderState.minutes = 0 recorderState.minutes = 0
} }
}, 1000) }, 1000);
} }
function stopTimer() { function stopTimer() {
recorderState.seconds = 0 recorderState.seconds = 0;
recorderState.minutes = 0 recorderState.minutes = 0;
recorderState.hours = 0 recorderState.hours = 0;
clearInterval(timer) clearInterval(timer);
timer = null timer = null;
} }
function timeComponentToString(value) { function timeComponentToString(value) {
return value.toString().padStart(2, '0') return value.toString().padStart(2, '0');
} }
</script> </script>

Loading…
Cancel
Save