pleroma-fe/src/components/video_attachment/video_attachment.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2026-02-13 14:26:39 +02:00
import { useSyncConfigStore } from 'src/stores/sync_config.js'
2019-01-26 17:45:03 +02:00
const VideoAttachment = {
props: ['attachment', 'controls'],
2026-01-06 16:22:52 +02:00
data() {
2019-01-26 17:45:03 +02:00
return {
2020-09-29 10:18:37 +00:00
blocksSuspend: false,
// Start from true because removing "loop" property seems buggy in Vue
2026-01-06 16:22:52 +02:00
hasAudio: true,
2020-09-29 10:18:37 +00:00
}
},
computed: {
2026-01-06 16:22:52 +02:00
loopVideo() {
2026-02-13 14:26:39 +02:00
if (useSyncConfigStore().mergedConfig.loopVideoSilentOnly) {
2020-09-29 10:18:37 +00:00
return !this.hasAudio
}
2026-02-13 14:26:39 +02:00
return useSyncConfigStore().mergedConfig.loopVideo
2026-01-06 16:22:52 +02:00
},
2019-01-26 17:45:03 +02:00
},
methods: {
2026-01-06 16:22:52 +02:00
onPlaying(e) {
2020-09-29 10:18:37 +00:00
this.setHasAudio(e)
if (this.loopVideo) {
this.$emit('play', { looping: true })
return
}
this.$emit('play')
},
2026-01-06 16:22:52 +02:00
onPaused() {
2020-09-29 10:18:37 +00:00
this.$emit('pause')
},
2026-01-06 16:22:52 +02:00
setHasAudio(e) {
2019-01-26 17:45:03 +02: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 17:45:03 +02: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 17:45:03 +02: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 17:45:03 +02:00
}
2020-09-29 10:18:37 +00:00
this.hasAudio = false
2026-01-06 16:22:52 +02:00
},
},
2019-01-26 17:45:03 +02:00
}
export default VideoAttachment