-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathVideos.vue
193 lines (171 loc) · 4.69 KB
/
Videos.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!--
- @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
-
- @author John Molakvoæ <skjnldsv@protonmail.com>
-
- @license AGPL-3.0-or-later
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<!-- Plyr currently replaces the parent. Wrapping to prevent this
https://github.com/redxtech/vue-plyr/issues/259 -->
<div v-if="src">
<VuePlyr ref="plyr"
:options="options"
:style="{
height: height + 'px',
width: width + 'px'
}">
<video ref="video"
:autoplay="active ? true : null"
:playsinline="true"
:poster="livePhotoPath"
:src="src"
preload="metadata"
@ended="donePlaying"
@canplay="doneLoading"
@loadedmetadata="onLoadedMetadata">
<!-- Omitting `type` on purpose because most of the
browsers auto detect the appropriate codec.
Having it set force the browser to comply to
the provided mime instead of detecting a potential
compatibility. -->
{{ t('viewer', 'Your browser does not support videos.') }}
</video>
</VuePlyr>
</div>
</template>
<script>
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import '@skjnldsv/vue-plyr/dist/vue-plyr.css'
import logger from '../services/logger.js'
const liveExt = ['jpg', 'jpeg', 'png']
const liveExtRegex = new RegExp(`\\.(${liveExt.join('|')})$`, 'i')
Vue.use(VuePlyr)
export default {
name: 'Videos',
computed: {
livePhoto() {
return this.fileList.find(file => {
// if same filename and extension is allowed
return file.filename !== this.filename
&& file.basename.startsWith(this.name)
&& liveExtRegex.test(file.basename)
})
},
livePhotoPath() {
return this.livePhoto && this.getPreviewIfAny(this.livePhoto)
},
player() {
return this.$refs.plyr.player
},
options() {
return {
autoplay: this.active === true,
// Used to reset the video streams https://github.com/sampotts/plyr#javascript-1
blankVideo: 'blank.mp4',
controls: ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'fullscreen'],
loadSprite: false,
}
},
},
watch: {
active(val, old) {
// the item was hidden before and is now the current view
if (val === true && old === false) {
this.player.play()
// the item was playing before and is now hidden
} else if (val === false && old === true) {
this.player.pause()
}
},
},
mounted() {
// Prevent swiping to the next/previous item when scrubbing the timeline or changing volume
[...this.$el.querySelectorAll('.plyr__controls__item')].forEach(control => {
if (!control?.addEventListener) {
return
}
control.addEventListener('mouseenter', this.disableSwipe)
control.addEventListener('mouseleave', this.enableSwipe)
})
},
beforeDestroy() {
// Force stop any ongoing request
logger.debug('Closing video stream', { filename: this.filename })
this.$refs.video.pause()
this.player.stop()
this.player.destroy()
},
methods: {
// Updates the dimensions of the modal
updateVideoSize() {
this.naturalHeight = this.$refs.video?.videoHeight
this.naturalWidth = this.$refs.video?.videoWidth
this.updateHeightWidth()
},
donePlaying() {
// reset and show poster after play
this.$refs.video.autoplay = false
this.$refs.video.load()
},
onLoadedMetadata() {
this.updateVideoSize()
// Force any further loading once we have the metadata
if (!this.active) {
this.player.stop()
}
},
},
}
</script>
<style scoped lang="scss">
video {
/* over arrows in tiny screens */
z-index: 20050;
align-self: center;
max-width: 100%;
max-height: 100%;
background-color: black;
justify-self: center;
}
::v-deep {
.plyr:-webkit-full-screen video {
width: 100% !important;
height: 100% !important;
}
.plyr:fullscreen video {
width: 100% !important;
height: 100% !important;
}
.plyr__progress__container {
flex: 1 1;
}
.plyr {
@import '../mixins/Plyr';
// Override server font style
button {
color: white;
&:hover,
&:focus {
color: var(--color-primary-text);
background-color: var(--color-primary-element);
}
}
}
}
</style>