invert hasAudio logic

This commit is contained in:
Shpuld Shpuldson 2020-09-04 15:31:22 +03:00
parent 14e6c0354d
commit 5a447cc2ad

View file

@ -4,7 +4,8 @@ const VideoAttachment = {
data () { data () {
return { return {
blocksSuspend: false, blocksSuspend: false,
hasAudio: false // Start from true because removing "loop" property seems buggy in Vue
hasAudio: true
} }
}, },
computed: { computed: {
@ -29,26 +30,21 @@ const VideoAttachment = {
}, },
setHasAudio (e) { setHasAudio (e) {
const target = e.srcElement || e.target const target = e.srcElement || e.target
// If hasAudio is true, we've already marked this video to have audio, // If hasAudio is false, we've already marked this video to not have audio,
// videos can never lose audio so don't bother checking again. // a video can't gain audio out of nowhere so don't bother checking again.
if (this.hasAudio) return if (!this.hasAudio) return
if (typeof target.webkitAudioDecodedByteCount !== 'undefined') { if (typeof target.webkitAudioDecodedByteCount !== 'undefined') {
// non-zero if video has audio track // non-zero if video has audio track
if (target.webkitAudioDecodedByteCount > 0) { if (target.webkitAudioDecodedByteCount > 0) return
this.hasAudio = true
}
} }
if (typeof target.mozHasAudio !== 'undefined') { if (typeof target.mozHasAudio !== 'undefined') {
// true if video has audio track // true if video has audio track
if (target.mozHasAudio) { if (target.mozHasAudio) return
this.hasAudio = true
}
} }
if (typeof target.audioTracks !== 'undefined') { if (typeof target.audioTracks !== 'undefined') {
if (target.audioTracks.length > 0) { if (target.audioTracks.length > 0) return
this.hasAudio = true
}
} }
this.hasAudio = false
} }
} }
} }