|
| 1 | +<!-- |
| 2 | + - @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de> |
| 3 | + - |
| 4 | + - @author Daniel Kesselberg <mail@danielkesselberg.de> |
| 5 | + - |
| 6 | + - @license GNU AGPL version 3 or any later version |
| 7 | + - |
| 8 | + - This program is free software: you can redistribute it and/or modify |
| 9 | + - it under the terms of the GNU Affero General Public License as |
| 10 | + - published by the Free Software Foundation, either version 3 of the |
| 11 | + - License, or (at your option) any later version. |
| 12 | + - |
| 13 | + - This program is distributed in the hope that it will be useful, |
| 14 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + - GNU Affero General Public License for more details. |
| 17 | + - |
| 18 | + - You should have received a copy of the GNU Affero General Public License |
| 19 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + - |
| 21 | + --> |
| 22 | + |
| 23 | +<template> |
| 24 | + <!-- Plyr currently replaces the parent. Wrapping to prevent this |
| 25 | + https://github.com/redxtech/vue-plyr/issues/259 --> |
| 26 | + <div v-if="davPath"> |
| 27 | + <VuePlyr |
| 28 | + ref="plyr" |
| 29 | + :options="options"> |
| 30 | + <audio |
| 31 | + ref="audio" |
| 32 | + :autoplay="active" |
| 33 | + :src="davPath" |
| 34 | + preload="metadata" |
| 35 | + @ended="donePlaying" |
| 36 | + @canplay="doneLoading"> |
| 37 | + |
| 38 | + <!-- Omitting `type` on purpose because most of the |
| 39 | + browsers auto detect the appropriate codec. |
| 40 | + Having it set force the browser to comply to |
| 41 | + the provided mime instead of detecting a potential |
| 42 | + compatibility. --> |
| 43 | + |
| 44 | + {{ t('viewer', 'Your browser does not support audio.') }} |
| 45 | + </audio> |
| 46 | + </VuePlyr> |
| 47 | + </div> |
| 48 | +</template> |
| 49 | + |
| 50 | +<script> |
| 51 | +import Vue from 'vue' |
| 52 | +import VuePlyr from '@skjnldsv/vue-plyr' |
| 53 | +import '@skjnldsv/vue-plyr/dist/vue-plyr.css' |
| 54 | +import logger from '../services/logger' |
| 55 | + |
| 56 | +Vue.use(VuePlyr) |
| 57 | + |
| 58 | +export default { |
| 59 | + name: 'Audios', |
| 60 | + |
| 61 | + computed: { |
| 62 | + player() { |
| 63 | + return this.$refs.plyr.player |
| 64 | + }, |
| 65 | + options() { |
| 66 | + return { |
| 67 | + autoplay: this.active === true, |
| 68 | + // Used to reset the audio streams https://github.com/sampotts/plyr#javascript-1 |
| 69 | + blankVideo: '/blank.aac', |
| 70 | + controls: ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'settings'], |
| 71 | + loadSprite: false, |
| 72 | + } |
| 73 | + }, |
| 74 | + }, |
| 75 | + |
| 76 | + watch: { |
| 77 | + active(val, old) { |
| 78 | + // the item was hidden before and is now the current view |
| 79 | + if (val === true && old === false) { |
| 80 | + this.player.play() |
| 81 | + |
| 82 | + // the item was playing before and is now hidden |
| 83 | + } else if (val === false && old === true) { |
| 84 | + this.player.pause() |
| 85 | + } |
| 86 | + }, |
| 87 | + }, |
| 88 | + |
| 89 | + mounted() { |
| 90 | + // Prevent swiping to the next/previous item when scrubbing the timeline or changing volume |
| 91 | + [...this.$el.querySelectorAll('.plyr__controls__item')].forEach(control => { |
| 92 | + if (!control?.addEventListener) { |
| 93 | + return |
| 94 | + } |
| 95 | + control.addEventListener('mouseenter', this.disableSwipe) |
| 96 | + control.addEventListener('mouseleave', this.enableSwipe) |
| 97 | + }) |
| 98 | + }, |
| 99 | + |
| 100 | + beforeDestroy() { |
| 101 | + // Force stop any ongoing request |
| 102 | +<<<<<<< HEAD |
| 103 | + logger.debug('Closing audio stream', { filename: this.filename }) |
| 104 | +======= |
| 105 | + console.debug('Closing audio stream', { filename: this.filename }) |
| 106 | +>>>>>>> 12b5579 (Properly cancel and reset ongoing streams when unmounting) |
| 107 | + this.$refs.audio.pause() |
| 108 | + this.player.stop() |
| 109 | + this.player.destroy() |
| 110 | + }, |
| 111 | + |
| 112 | + methods: { |
| 113 | + donePlaying() { |
| 114 | + this.$refs.audio.autoplay = false |
| 115 | + this.$refs.audio.load() |
| 116 | + }, |
| 117 | + }, |
| 118 | +} |
| 119 | +</script> |
| 120 | + |
| 121 | +<style scoped lang="scss"> |
| 122 | +audio { |
| 123 | + background-color: black; |
| 124 | + max-width: 100%; |
| 125 | + max-height: 100%; |
| 126 | + align-self: center; |
| 127 | + justify-self: center; |
| 128 | + /* over arrows in tiny screens */ |
| 129 | + z-index: 20050; |
| 130 | +} |
| 131 | + |
| 132 | +::v-deep { |
| 133 | + .plyr__progress__container { |
| 134 | + flex: 1 1; |
| 135 | + } |
| 136 | + .plyr__volume { |
| 137 | + min-width: 80px; |
| 138 | + } |
| 139 | + // plyr buttons style |
| 140 | + .plyr--audio .plyr__progress__buffer, |
| 141 | + .plyr--audio .plyr__control { |
| 142 | + &.plyr__tab-focus, |
| 143 | + &:hover, |
| 144 | + &[aria-expanded=true] { |
| 145 | + background-color: var(--color-primary-element); |
| 146 | + color: var(--color-primary-text); |
| 147 | + box-shadow: none !important; |
| 148 | + } |
| 149 | + } |
| 150 | + // plyr volume control |
| 151 | + .plyr--full-ui input[type=range] { |
| 152 | + color: var(--color-primary-element); |
| 153 | + } |
| 154 | +} |
| 155 | +</style> |
0 commit comments