2019-01-26 15:45:03 +00:00
|
|
|
|
|
|
|
const VideoAttachment = {
|
|
|
|
props: ['attachment', 'controls'],
|
|
|
|
data () {
|
|
|
|
return {
|
2020-09-29 10:18:37 +00:00
|
|
|
blocksSuspend: false,
|
|
|
|
// Start from true because removing "loop" property seems buggy in Vue
|
|
|
|
hasAudio: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
loopVideo () {
|
|
|
|
if (this.$store.getters.mergedConfig.loopVideoSilentOnly) {
|
|
|
|
return !this.hasAudio
|
|
|
|
}
|
|
|
|
return this.$store.getters.mergedConfig.loopVideo
|
2019-01-26 15:45:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-09-29 10:18:37 +00:00
|
|
|
onPlaying (e) {
|
|
|
|
this.setHasAudio(e)
|
|
|
|
if (this.loopVideo) {
|
|
|
|
this.$emit('play', { looping: true })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.$emit('play')
|
|
|
|
},
|
|
|
|
onPaused (e) {
|
|
|
|
this.$emit('pause')
|
|
|
|
},
|
|
|
|
setHasAudio (e) {
|
2019-01-26 15:45:03 +00:00
|
|
|
const target = e.srcElement || e.target
|
2020-09-29 10:18:37 +00:00
|
|
|
// If hasAudio is false, we've already marked this video to not have audio,
|
|
|
|
// a video can't gain audio out of nowhere so don't bother checking again.
|
|
|
|
if (!this.hasAudio) return
|
2019-01-26 15:45:03 +00:00
|
|
|
if (typeof target.webkitAudioDecodedByteCount !== 'undefined') {
|
|
|
|
// non-zero if video has audio track
|
2020-09-29 10:18:37 +00:00
|
|
|
if (target.webkitAudioDecodedByteCount > 0) return
|
|
|
|
}
|
|
|
|
if (typeof target.mozHasAudio !== 'undefined') {
|
2019-01-26 15:45:03 +00:00
|
|
|
// true if video has audio track
|
2020-09-29 10:18:37 +00:00
|
|
|
if (target.mozHasAudio) return
|
|
|
|
}
|
|
|
|
if (typeof target.audioTracks !== 'undefined') {
|
|
|
|
if (target.audioTracks.length > 0) return
|
2019-01-26 15:45:03 +00:00
|
|
|
}
|
2020-09-29 10:18:37 +00:00
|
|
|
this.hasAudio = false
|
2019-01-26 15:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VideoAttachment
|