repod/src/components/Player/Bar.vue

129 lines
2.8 KiB
Vue
Raw Normal View History

2023-08-24 20:29:11 +00:00
<template>
2023-08-27 18:01:26 +00:00
<div v-if="episode" class="footer">
<audio id="audio-player"
autoplay
preload
:src="episode.episodeUrl"
2023-08-27 18:29:54 +00:00
@durationchange="duration = audio.duration"
2023-08-28 16:18:25 +00:00
@loadeddata="loadeddata"
2023-08-28 15:44:17 +00:00
@pause="pause"
2023-08-27 22:02:07 +00:00
@play="paused = false"
2023-08-27 18:01:26 +00:00
@seeked="currentTime = audio.currentTime"
2023-08-27 18:29:54 +00:00
@timeupdate="currentTime = audio.currentTime"
2023-08-27 18:01:26 +00:00
@volumechange="volume = audio.volume" />
<NcLoadingIcon v-if="loading" />
2023-08-27 20:20:34 +00:00
<ProgressBar v-if="!loading"
:current-time="currentTime"
:duration="duration" />
2023-08-27 18:01:26 +00:00
<div v-if="!loading" class="player">
<img :src="episode.episodeImage">
2023-08-28 16:18:25 +00:00
<Infos :podcast-url="podcastUrl" />
2023-08-27 20:20:34 +00:00
<Controls :paused="paused" />
<Timer class="timer"
:current-time="currentTime"
:duration="duration" />
<Volume class="volume" :volume="volume" />
2023-08-24 21:19:54 +00:00
</div>
2023-08-27 18:01:26 +00:00
</div>
2023-08-24 20:29:11 +00:00
</template>
<script>
2023-08-27 20:20:34 +00:00
import Controls from './Controls.vue'
import Infos from './Infos.vue'
import { NcLoadingIcon } from '@nextcloud/vue'
import ProgressBar from './ProgressBar.vue'
import Timer from './Timer.vue'
import Volume from './Volume.vue'
2023-08-28 15:44:17 +00:00
import axios from '@nextcloud/axios'
import { formatEpisodeTimestamp } from '../../utils/time.js'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
2023-08-27 10:45:19 +00:00
2023-08-24 20:29:11 +00:00
export default {
name: 'Bar',
2023-08-27 10:45:19 +00:00
components: {
2023-08-27 20:20:34 +00:00
Controls,
Infos,
2023-08-27 18:01:26 +00:00
NcLoadingIcon,
2023-08-27 20:20:34 +00:00
ProgressBar,
Timer,
Volume,
2023-08-27 10:45:19 +00:00
},
2023-08-27 18:01:26 +00:00
data() {
return {
currentTime: 0,
2023-08-27 18:29:54 +00:00
duration: 0,
2023-08-27 18:01:26 +00:00
loading: true,
2023-08-27 20:48:21 +00:00
paused: false,
2023-08-28 16:18:25 +00:00
podcastUrl: atob(this.$route.params.url),
2023-08-27 19:33:39 +00:00
volume: 1,
2023-08-27 18:01:26 +00:00
}
},
2023-08-24 20:29:11 +00:00
computed: {
2023-08-27 10:45:19 +00:00
audio() {
2023-08-27 18:01:26 +00:00
return document.getElementById('audio-player')
2023-08-27 10:45:19 +00:00
},
2023-08-24 21:19:54 +00:00
episode() {
return this.$store.state.player.episode
2023-08-24 20:29:11 +00:00
},
},
2023-08-28 15:44:17 +00:00
methods: {
2023-08-28 16:18:25 +00:00
loadeddata() {
this.loading = false
if (this.episode.episodeAction) {
this.audio.currentTime = this.episode.episodeAction.position
}
},
2023-08-28 15:44:17 +00:00
pause() {
this.paused = true
this.track()
},
async track() {
try {
await axios.post(generateUrl('/apps/gpoddersync/episode_action/create'), [{
podcast: this.podcastUrl,
episode: this.episode.episodeUrl,
guid: this.episode.episodeGuid,
action: 'play',
timestamp: formatEpisodeTimestamp(new Date()),
2023-08-28 16:18:25 +00:00
started: Math.round(this.episode.episodeAction ? this.episode.episodeAction.started : 0),
position: Math.round(this.currentTime),
total: Math.round(this.duration),
2023-08-28 15:44:17 +00:00
}])
} catch (e) {
console.error(e)
showError(t('Error while saving position on API'))
}
},
},
2023-08-24 20:29:11 +00:00
}
</script>
<style scoped>
2023-08-24 21:19:54 +00:00
.footer {
2023-08-27 10:45:19 +00:00
background-color: rgba(66, 66, 66, .9);
2023-08-24 21:59:55 +00:00
bottom: 0;
2023-08-27 10:45:19 +00:00
height: 6rem;
2023-08-24 21:59:55 +00:00
right: 0;
2023-08-24 20:29:11 +00:00
position: absolute;
width: 100%;
2023-08-24 21:59:55 +00:00
z-index: 2000;
2023-08-24 20:29:11 +00:00
}
2023-08-27 10:45:19 +00:00
.player {
display: flex;
gap: 1rem;
height: calc(6rem - 6px);
2023-08-27 19:33:39 +00:00
justify-content: space-between;
2023-08-27 10:45:19 +00:00
}
2023-08-27 18:01:26 +00:00
2023-08-27 20:20:34 +00:00
.timer {
2023-08-28 16:18:25 +00:00
width: 30%;
2023-08-27 19:33:39 +00:00
}
.volume {
width: 10%;
}
2023-08-24 20:29:11 +00:00
</style>