keanu-weblite/src/components/messages/AudioPlayer.vue

73 lines
1.8 KiB
Vue
Raw Normal View History

2021-05-07 11:30:24 +02:00
<template>
<div class="audio-player d-flex flex-row align-center">
<v-progress-circular v-if="info.loading" @click.stop="pause" :value="info.loadPercent" size="24" width="2" style="margin:6px"></v-progress-circular>
<v-btn v-else-if="info.playing" id="btn-pause" @click.stop="pause" icon><v-icon size="20">pause</v-icon></v-btn>
<v-btn v-else id="btn-play" @click.stop="play" icon><v-icon size="20">play_arrow</v-icon></v-btn>
<div class="play-time">
2021-05-07 11:30:24 +02:00
{{ currentTime }} / {{ totalTime }}
</div>
<v-slider @change="seeked" :disabled="!info.url" color="currentColor" track-color="#cccccc" class="play-progress" :value="info.playPercent" min="0"
max="100" />
2021-05-07 11:30:24 +02:00
</div>
</template>
<script>
import util from "../../plugins/utils";
export default {
props: {
event: {
type: Object,
2021-05-07 11:30:24 +02:00
default: function () {
return null;
},
},
timelineSet: {
type: Object,
default: function () {
return null;
},
},
2021-05-07 11:30:24 +02:00
},
data() {
return {
info: this.install(),
2021-05-07 11:30:24 +02:00
};
},
2022-04-11 12:09:51 +00:00
beforeDestroy() {
this.$audioPlayer.removeListener(this._uid);
2022-04-11 12:09:51 +00:00
},
2021-05-07 11:30:24 +02:00
computed: {
currentTime() {
return util.formatDuration(this.info.currentTime);
2021-05-07 11:30:24 +02:00
},
totalTime() {
return util.formatDuration(this.info.duration);
2021-05-07 11:30:24 +02:00
},
},
methods: {
install() {
return this.$audioPlayer.addListener(this._uid, this.event);
},
2021-05-07 11:30:24 +02:00
play() {
this.$audioPlayer.play(this.event, this.timelineSet);
2021-05-07 11:30:24 +02:00
},
pause() {
this.$audioPlayer.pause(this.event);
2021-05-07 11:30:24 +02:00
},
2022-04-11 12:09:51 +00:00
onPlaybackStart(item) {
if (item != this.src && this.info.playing) {
2022-04-11 12:09:51 +00:00
this.pause();
}
},
seeked(percent) {
this.$audioPlayer.seek(this.event, percent);
2022-04-11 12:09:51 +00:00
}
2021-05-07 11:30:24 +02:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>