make playing videos stop the suspending

This commit is contained in:
Shpuld Shpuldson 2020-03-11 19:10:39 +02:00
commit 42e43511de
8 changed files with 83 additions and 25 deletions

View file

@ -3,25 +3,53 @@ const VideoAttachment = {
props: ['attachment', 'controls'],
data () {
return {
loopVideo: this.$store.getters.mergedConfig.loopVideo
blocksSuspend: false,
hasAudio: false
}
},
computed: {
loopVideo () {
if (this.$store.getters.mergedConfig.loopVideoSilentOnly) {
console.log('do I have audio', this.hasAudio)
return !this.hasAudio
}
return this.$store.getters.mergedConfig.loopVideo
}
},
methods: {
onVideoDataLoad (e) {
onPlaying (e) {
// Don't bother stopping suspend on small looping gif-like videos
this.checkForAudio(e)
if (this.loopVideo) {
return
}
this.$emit('play')
},
onPaused (e) {
this.$emit('pause')
},
checkForAudio (e) {
const target = e.srcElement || e.target
if (this.hasAudio) return
console.log(target.webkitAudioDecodedByteCount)
if (typeof target.webkitAudioDecodedByteCount !== 'undefined') {
// non-zero if video has audio track
if (target.webkitAudioDecodedByteCount > 0) {
this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly
console.log('1')
this.hasAudio = true
}
} else if (typeof target.mozHasAudio !== 'undefined') {
}
if (typeof target.mozHasAudio !== 'undefined') {
// true if video has audio track
if (target.mozHasAudio) {
this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly
console.log('2')
this.hasAudio = true
}
} else if (typeof target.audioTracks !== 'undefined') {
}
if (typeof target.audioTracks !== 'undefined') {
if (target.audioTracks.length > 0) {
this.loopVideo = this.loopVideo && !this.$store.getters.mergedConfig.loopVideoSilentOnly
console.log('3')
this.hasAudio = true
}
}
}

View file

@ -5,7 +5,8 @@
:loop="loopVideo"
:controls="controls"
playsinline
@loadeddata="onVideoDataLoad"
@playing="onPlaying"
@pause="onPaused"
/>
</template>