2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-11-26 22:46:07 +01:00
|
|
|
<div class="w-full -mt-6">
|
|
|
|
<div class="w-full relative mb-1">
|
2022-03-05 19:30:46 +01:00
|
|
|
<div class="absolute -top-10 md:top-0 right-0 md:right-2 flex items-center h-full">
|
2022-06-01 03:13:46 +02:00
|
|
|
<span class="material-icons text-2xl cursor-pointer" @click="toggleFullscreen(true)">expand_less</span>
|
|
|
|
|
2022-03-05 19:30:46 +01:00
|
|
|
<controls-volume-control ref="volumeControl" v-model="volume" @input="setVolume" class="mx-2 hidden md:block" />
|
|
|
|
|
|
|
|
<div class="cursor-pointer text-gray-300 mx-1 md:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="$emit('showSleepTimer')">
|
|
|
|
<span v-if="!sleepTimerSet" class="material-icons" style="font-size: 1.7rem">snooze</span>
|
|
|
|
<div v-else class="flex items-center">
|
|
|
|
<span class="material-icons text-lg text-warning">snooze</span>
|
|
|
|
<p class="text-xl text-warning font-mono font-semibold text-center px-0.5 pb-0.5" style="min-width: 30px">{{ sleepTimerRemainingString }}</p>
|
|
|
|
</div>
|
2021-09-08 16:15:54 +02:00
|
|
|
</div>
|
2022-03-05 19:30:46 +01:00
|
|
|
|
2022-04-12 02:42:09 +02:00
|
|
|
<div v-if="!isPodcast" class="cursor-pointer text-gray-300 mx-1 md:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="$emit('showBookmarks')">
|
2021-10-27 03:09:04 +02:00
|
|
|
<span class="material-icons" style="font-size: 1.7rem">{{ bookmarks.length ? 'bookmarks' : 'bookmark_border' }}</span>
|
2021-10-25 01:25:44 +02:00
|
|
|
</div>
|
2022-03-05 19:30:46 +01:00
|
|
|
|
|
|
|
<div v-if="chapters.length" class="cursor-pointer text-gray-300 mx-1 md:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="showChapters">
|
|
|
|
<span class="material-icons text-3xl">format_list_bulleted</span>
|
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
|
2022-06-01 03:13:46 +02:00
|
|
|
<player-playback-controls :loading="loading" :seek-loading="seekLoading" :playback-rate="playbackRate" :paused="paused" @restart="restart" @jumpForward="jumpForward" @jumpBackward="jumpBackward" @setPlaybackRate="setPlaybackRate" @playPause="playPause" />
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
|
2022-06-01 03:13:46 +02:00
|
|
|
<player-track-bar ref="trackbar" :loading="loading" :chapters="chapters" :duration="duration" @seek="seek" />
|
|
|
|
|
2021-11-26 22:46:07 +01:00
|
|
|
<div class="flex">
|
|
|
|
<p ref="currentTimestamp" class="font-mono text-sm text-gray-100 pointer-events-auto">00:00:00</p>
|
|
|
|
<p class="font-mono text-sm text-gray-100 pointer-events-auto"> / {{ progressPercent }}%</p>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<p class="text-sm text-gray-300 pt-0.5">{{ currentChapterName }}</p>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<p class="font-mono text-sm text-gray-100 pointer-events-auto">{{ timeRemainingPretty }}</p>
|
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
|
2021-09-21 23:42:01 +02:00
|
|
|
<modals-chapters-modal v-model="showChaptersModal" :current-chapter="currentChapter" :chapters="chapters" @select="selectChapter" />
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2021-09-08 16:15:54 +02:00
|
|
|
loading: Boolean,
|
2022-02-23 00:33:55 +01:00
|
|
|
paused: Boolean,
|
2021-09-08 16:15:54 +02:00
|
|
|
chapters: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
|
|
|
bookmarks: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2022-03-05 19:30:46 +01:00
|
|
|
},
|
|
|
|
sleepTimerSet: Boolean,
|
2022-04-12 02:42:09 +02:00
|
|
|
sleepTimerRemaining: Number,
|
|
|
|
isPodcast: Boolean
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-10-21 01:54:05 +02:00
|
|
|
volume: 1,
|
2021-08-21 01:29:10 +02:00
|
|
|
playbackRate: 1,
|
2021-08-18 00:01:11 +02:00
|
|
|
audioEl: null,
|
2021-09-08 16:15:54 +02:00
|
|
|
seekLoading: false,
|
2021-09-21 23:42:01 +02:00
|
|
|
showChaptersModal: false,
|
2021-09-22 00:28:43 +02:00
|
|
|
currentTime: 0,
|
2022-06-01 03:13:46 +02:00
|
|
|
duration: 0
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-03-05 19:30:46 +01:00
|
|
|
sleepTimerRemainingString() {
|
|
|
|
var rounded = Math.round(this.sleepTimerRemaining)
|
|
|
|
if (rounded < 90) {
|
|
|
|
return `${rounded}s`
|
|
|
|
}
|
|
|
|
var minutesRounded = Math.round(rounded / 60)
|
|
|
|
if (minutesRounded < 90) {
|
|
|
|
return `${minutesRounded}m`
|
|
|
|
}
|
|
|
|
var hoursRounded = Math.round(minutesRounded / 60)
|
|
|
|
return `${hoursRounded}h`
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
token() {
|
2021-08-24 01:31:04 +02:00
|
|
|
return this.$store.getters['user/getToken']
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-10-25 01:25:44 +02:00
|
|
|
timeRemaining() {
|
2022-02-23 00:33:55 +01:00
|
|
|
return (this.duration - this.currentTime) / this.playbackRate
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
|
|
|
timeRemainingPretty() {
|
2021-11-13 02:43:16 +01:00
|
|
|
if (this.timeRemaining < 0) {
|
|
|
|
return this.$secondsToTimestamp(this.timeRemaining * -1)
|
|
|
|
}
|
2021-10-25 01:25:44 +02:00
|
|
|
return '-' + this.$secondsToTimestamp(this.timeRemaining)
|
|
|
|
},
|
|
|
|
progressPercent() {
|
2022-02-23 00:33:55 +01:00
|
|
|
if (!this.duration) return 0
|
|
|
|
return Math.round((100 * this.currentTime) / this.duration)
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2021-09-21 23:42:01 +02:00
|
|
|
currentChapter() {
|
|
|
|
return this.chapters.find((chapter) => chapter.start <= this.currentTime && this.currentTime < chapter.end)
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2021-11-26 22:46:07 +01:00
|
|
|
currentChapterName() {
|
|
|
|
return this.currentChapter ? this.currentChapter.title : ''
|
2022-06-01 03:13:46 +02:00
|
|
|
},
|
|
|
|
isFullscreen() {
|
|
|
|
return this.$store.state.playerIsFullscreen
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-06-01 03:13:46 +02:00
|
|
|
toggleFullscreen(isFullscreen) {
|
|
|
|
this.$store.commit('setPlayerIsFullscreen', isFullscreen)
|
2022-03-05 22:37:30 +01:00
|
|
|
|
2022-06-01 03:13:46 +02:00
|
|
|
var videoPlayerEl = document.getElementById('video-player')
|
|
|
|
if (videoPlayerEl) {
|
|
|
|
if (isFullscreen) {
|
|
|
|
videoPlayerEl.style.width = '100vw'
|
|
|
|
videoPlayerEl.style.height = '100vh'
|
|
|
|
videoPlayerEl.style.top = '0px'
|
|
|
|
videoPlayerEl.style.left = '0px'
|
|
|
|
} else {
|
|
|
|
videoPlayerEl.style.width = '384px'
|
|
|
|
videoPlayerEl.style.height = '216px'
|
|
|
|
videoPlayerEl.style.top = 'unset'
|
|
|
|
videoPlayerEl.style.bottom = '80px'
|
|
|
|
videoPlayerEl.style.left = '16px'
|
2022-03-05 22:37:30 +01:00
|
|
|
}
|
2022-06-01 03:13:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setDuration(duration) {
|
|
|
|
this.duration = duration
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
|
|
|
setCurrentTime(time) {
|
|
|
|
this.currentTime = time
|
|
|
|
this.updateTimestamp()
|
2022-06-01 03:13:46 +02:00
|
|
|
if (this.$refs.trackbar) this.$refs.trackbar.setCurrentTime(time)
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
|
|
|
playPause() {
|
|
|
|
this.$emit('playPause')
|
|
|
|
},
|
|
|
|
jumpBackward() {
|
|
|
|
this.$emit('jumpBackward')
|
|
|
|
},
|
|
|
|
jumpForward() {
|
|
|
|
this.$emit('jumpForward')
|
|
|
|
},
|
|
|
|
increaseVolume() {
|
|
|
|
if (this.volume >= 1) return
|
|
|
|
this.volume = Math.min(1, this.volume + 0.1)
|
|
|
|
this.setVolume(this.volume)
|
|
|
|
},
|
|
|
|
decreaseVolume() {
|
|
|
|
if (this.volume <= 0) return
|
|
|
|
this.volume = Math.max(0, this.volume - 0.1)
|
|
|
|
this.setVolume(this.volume)
|
|
|
|
},
|
|
|
|
setVolume(volume) {
|
|
|
|
this.$emit('setVolume', volume)
|
|
|
|
},
|
|
|
|
toggleMute() {
|
|
|
|
if (this.$refs.volumeControl && this.$refs.volumeControl.toggleMute) {
|
|
|
|
this.$refs.volumeControl.toggleMute()
|
2021-11-13 02:43:16 +01:00
|
|
|
}
|
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
increasePlaybackRate() {
|
|
|
|
var rates = [0.25, 0.5, 0.8, 1, 1.3, 1.5, 2, 2.5, 3]
|
|
|
|
var currentRateIndex = rates.findIndex((r) => r === this.playbackRate)
|
|
|
|
if (currentRateIndex >= rates.length - 1) return
|
|
|
|
this.playbackRate = rates[currentRateIndex + 1] || 1
|
|
|
|
this.playbackRateChanged(this.playbackRate)
|
2021-11-13 02:43:16 +01:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
decreasePlaybackRate() {
|
|
|
|
var rates = [0.25, 0.5, 0.8, 1, 1.3, 1.5, 2, 2.5, 3]
|
|
|
|
var currentRateIndex = rates.findIndex((r) => r === this.playbackRate)
|
|
|
|
if (currentRateIndex <= 0) return
|
|
|
|
this.playbackRate = rates[currentRateIndex - 1] || 1
|
|
|
|
this.playbackRateChanged(this.playbackRate)
|
2021-11-13 02:43:16 +01:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setPlaybackRate(playbackRate) {
|
|
|
|
this.$emit('setPlaybackRate', playbackRate)
|
2021-11-13 02:43:16 +01:00
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
selectChapter(chapter) {
|
|
|
|
this.seek(chapter.start)
|
|
|
|
this.showChaptersModal = false
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
seek(time) {
|
2022-02-23 00:33:55 +01:00
|
|
|
this.$emit('seek', time)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
restart() {
|
|
|
|
this.seek(0)
|
|
|
|
},
|
|
|
|
setStreamReady() {
|
2022-06-01 03:13:46 +02:00
|
|
|
if (this.$refs.trackbar) this.$refs.trackbar.setPercentageReady(1)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
setChunksReady(chunks, numSegments) {
|
|
|
|
var largestSeg = 0
|
|
|
|
for (let i = 0; i < chunks.length; i++) {
|
|
|
|
var chunk = chunks[i]
|
|
|
|
if (typeof chunk === 'string') {
|
|
|
|
var chunkRange = chunk.split('-').map((c) => Number(c))
|
|
|
|
if (chunkRange.length < 2) continue
|
|
|
|
if (chunkRange[1] > largestSeg) largestSeg = chunkRange[1]
|
|
|
|
} else if (chunk > largestSeg) {
|
|
|
|
largestSeg = chunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var percentageReady = largestSeg / numSegments
|
2022-06-01 03:13:46 +02:00
|
|
|
if (this.$refs.trackbar) this.$refs.trackbar.setPercentageReady(percentageReady)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
updateTimestamp() {
|
|
|
|
var ts = this.$refs.currentTimestamp
|
|
|
|
if (!ts) {
|
|
|
|
console.error('No timestamp el')
|
|
|
|
return
|
|
|
|
}
|
2022-02-23 00:33:55 +01:00
|
|
|
var currTimeClean = this.$secondsToTimestamp(this.currentTime)
|
|
|
|
ts.innerText = currTimeClean
|
|
|
|
},
|
|
|
|
|
|
|
|
setBufferTime(bufferTime) {
|
2022-06-01 03:13:46 +02:00
|
|
|
if (this.$refs.trackbar) this.$refs.trackbar.setBufferTime(bufferTime)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
showChapters() {
|
2021-10-23 23:49:34 +02:00
|
|
|
if (!this.chapters.length) return
|
|
|
|
this.showChaptersModal = !this.showChaptersModal
|
2021-09-08 16:15:54 +02:00
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
init() {
|
2021-08-24 01:31:04 +02:00
|
|
|
this.playbackRate = this.$store.getters['user/getUserSetting']('playbackRate') || 1
|
2022-02-23 00:33:55 +01:00
|
|
|
this.$emit('setPlaybackRate', this.playbackRate)
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
|
|
|
settingsUpdated(settings) {
|
|
|
|
if (settings.playbackRate && this.playbackRate !== settings.playbackRate) {
|
2022-02-23 00:33:55 +01:00
|
|
|
this.setPlaybackRate(settings.playbackRate)
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
|
|
|
},
|
2021-10-23 23:49:34 +02:00
|
|
|
closePlayer() {
|
2022-06-01 03:13:46 +02:00
|
|
|
if (this.isFullscreen) {
|
|
|
|
this.toggleFullscreen(false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-23 23:49:34 +02:00
|
|
|
if (this.loading) return
|
|
|
|
this.$emit('close')
|
|
|
|
},
|
|
|
|
hotkey(action) {
|
2022-02-23 00:33:55 +01:00
|
|
|
if (action === this.$hotkeys.AudioPlayer.PLAY_PAUSE) this.playPause()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.JUMP_FORWARD) this.jumpForward()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.JUMP_BACKWARD) this.jumpBackward()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.VOLUME_UP) this.increaseVolume()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.VOLUME_DOWN) this.decreaseVolume()
|
2021-10-24 21:02:49 +02:00
|
|
|
else if (action === this.$hotkeys.AudioPlayer.MUTE_UNMUTE) this.toggleMute()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.SHOW_CHAPTERS) this.showChapters()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.INCREASE_PLAYBACK_RATE) this.increasePlaybackRate()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.DECREASE_PLAYBACK_RATE) this.decreasePlaybackRate()
|
|
|
|
else if (action === this.$hotkeys.AudioPlayer.CLOSE) this.closePlayer()
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-08-24 01:31:04 +02:00
|
|
|
this.$store.commit('user/addSettingsListener', { id: 'audioplayer', meth: this.settingsUpdated })
|
2021-08-19 01:31:19 +02:00
|
|
|
this.init()
|
2021-10-23 03:08:02 +02:00
|
|
|
this.$eventBus.$on('player-hotkey', this.hotkey)
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$store.commit('user/removeSettingsListener', 'audioplayer')
|
2021-10-23 03:08:02 +02:00
|
|
|
this.$eventBus.$off('player-hotkey', this.hotkey)
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-08-21 01:29:10 +02:00
|
|
|
<style>
|
2021-08-19 01:31:19 +02:00
|
|
|
.loadingTrack {
|
|
|
|
animation-name: loadingTrack;
|
|
|
|
animation-duration: 1s;
|
|
|
|
animation-iteration-count: infinite;
|
|
|
|
}
|
|
|
|
@keyframes loadingTrack {
|
|
|
|
0% {
|
|
|
|
left: -25%;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
left: 100%;
|
|
|
|
}
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
</style>
|