-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
oh-video-videojs.vue
70 lines (68 loc) · 1.52 KB
/
oh-video-videojs.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
<template>
<video
ref="videoPlayer"
class="video-js vjs-fluid"
:poster="computedPosterUrl">
Sorry, your browser doesn't support embedded videos.
</video>
</template>
<script>
import videojs from 'video.js'
import 'video.js/dist/video-js.css'
export default {
name: 'OhVideoVideojs',
props: {
src: { type: String },
type: { type: String },
config: { type: Object },
startManually: { type: Boolean },
hideControls: { type: Boolean },
posterURL: { type: String }
},
data () {
return {
player: null
}
},
watch: {
src (value) {
if (this.player) {
this.player.src({ type: this.type, src: this.src })
}
}
},
computed: {
computedPosterUrl () {
const ts = (new Date()).toISOString()
return this.posterURL ? this.posterURL.indexOf('?') === -1 ? `${this.posterURL}?_ts=${ts}` : `${this.posterURL}&_ts=${ts}` : this.posterURL
}
},
mounted () {
this.createPlayer()
},
beforeDestroy () {
if (this.player) {
this.player.dispose()
}
},
methods: {
createPlayer () {
if (this.player) {
this.player.dispose()
}
const playerOpts = Object.assign({}, {
liveui: true,
autoplay: this.startManually ? false : 'muted',
controls: !this.hideControls
}, this.config || {})
this.player = videojs(
this.$refs.videoPlayer,
playerOpts
)
if (this.src) {
this.player.src({ type: this.type, src: this.src })
}
}
}
}
</script>