repod/src/components/Player/Controls.vue

87 lines
1.8 KiB
Vue
Raw Normal View History

2023-08-27 22:20:34 +02:00
<template>
2023-08-28 21:18:14 +02:00
<div>
2023-08-27 22:20:34 +02:00
<PauseButton v-if="!paused"
class="pointer"
:size="50"
2023-08-28 18:29:26 +02:00
@click="pause" />
2023-08-27 22:20:34 +02:00
<PlayButton v-if="paused"
class="pointer"
:size="50"
@click="() => audio.play()" />
<StopButton class="pointer"
:size="30"
2023-08-28 17:44:17 +02:00
@click="stop" />
2023-08-28 21:18:14 +02:00
</div>
2023-08-27 22:20:34 +02:00
</template>
<script>
import PauseButton from 'vue-material-design-icons/Pause.vue'
import PlayButton from 'vue-material-design-icons/Play.vue'
import StopButton from 'vue-material-design-icons/Stop.vue'
2023-08-28 18:29:26 +02: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 22:20:34 +02:00
export default {
name: 'Controls',
components: {
PauseButton,
PlayButton,
StopButton,
},
props: {
paused: {
type: Boolean,
required: true,
},
},
2023-08-28 18:29:26 +02:00
data() {
return {
podcastUrl: atob(this.$route.params.url),
}
},
2023-08-27 22:20:34 +02:00
computed: {
audio() {
return document.getElementById('audio-player')
},
2023-08-28 18:29:26 +02:00
episode() {
return this.$store.state.player.episode
},
2023-08-27 22:20:34 +02:00
},
2023-08-28 17:44:17 +02:00
methods: {
2023-08-28 18:29:26 +02:00
pause() {
2023-08-28 17:44:17 +02:00
this.audio.pause()
2023-08-28 18:29:26 +02:00
this.track()
},
stop() {
this.pause()
2023-08-28 17:44:17 +02:00
this.$store.commit('player/play', null)
},
2023-08-28 18:29:26 +02:00
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()),
started: Math.round(this.episode.episodeAction ? this.episode.episodeAction.started : 0),
position: Math.round(this.audio.currentTime),
total: Math.round(this.audio.duration),
}])
} catch (e) {
console.error(e)
showError(t('Error while saving position on API'))
}
},
2023-08-28 17:44:17 +02:00
},
2023-08-27 22:20:34 +02:00
}
</script>
2023-08-28 00:02:07 +02:00
<style scoped>
.pointer {
cursor: pointer;
}
</style>