1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-24 16:36:46 +00:00
bramw_baserow/web-frontend/modules/database/components/preview/PreviewAudio.vue

52 lines
1.0 KiB
Vue

<template>
<div class="preview__audio-wrapper">
<div v-if="!loaded && canRead" class="preview__loading"></div>
<audio
v-show="canRead"
ref="audioRef"
controls
class="preview__audio"
:class="{ 'preview--hidden': !loaded }"
@loadstart="loaded = true"
>
<source :src="url" :type="mimeType" />
<slot name="fallback" />
</audio>
<slot v-if="!canRead" name="fallback" />
</div>
</template>
<script>
export default {
name: 'PreviewAudio',
props: {
url: {
type: String,
required: true,
},
mimeType: {
type: String,
required: true,
},
},
data() {
return {
loaded: false,
canRead: false,
}
},
mounted() {
if (this.$refs.audioRef.canPlayType(this.mimeType) !== '') {
// This format should be playable
this.canRead = true
}
},
methods: {
onError(e) {
// Actually this format can't be read, go back to fallback
this.canRead = false
},
},
}
</script>