make playing videos stop the suspending
This commit is contained in:
parent
ed4825da0b
commit
42e43511de
8 changed files with 83 additions and 25 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
:loop="loopVideo"
|
||||
:controls="controls"
|
||||
playsinline
|
||||
@loadeddata="onVideoDataLoad"
|
||||
@playing="onPlaying"
|
||||
@pause="onPaused"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue