logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

video_attachment.js (1445B)


  1. const VideoAttachment = {
  2. props: ['attachment', 'controls'],
  3. data () {
  4. return {
  5. blocksSuspend: false,
  6. // Start from true because removing "loop" property seems buggy in Vue
  7. hasAudio: true
  8. }
  9. },
  10. computed: {
  11. loopVideo () {
  12. if (this.$store.getters.mergedConfig.loopVideoSilentOnly) {
  13. return !this.hasAudio
  14. }
  15. return this.$store.getters.mergedConfig.loopVideo
  16. }
  17. },
  18. methods: {
  19. onPlaying (e) {
  20. this.setHasAudio(e)
  21. if (this.loopVideo) {
  22. this.$emit('play', { looping: true })
  23. return
  24. }
  25. this.$emit('play')
  26. },
  27. onPaused (e) {
  28. this.$emit('pause')
  29. },
  30. setHasAudio (e) {
  31. const target = e.srcElement || e.target
  32. // If hasAudio is false, we've already marked this video to not have audio,
  33. // a video can't gain audio out of nowhere so don't bother checking again.
  34. if (!this.hasAudio) return
  35. if (typeof target.webkitAudioDecodedByteCount !== 'undefined') {
  36. // non-zero if video has audio track
  37. if (target.webkitAudioDecodedByteCount > 0) return
  38. }
  39. if (typeof target.mozHasAudio !== 'undefined') {
  40. // true if video has audio track
  41. if (target.mozHasAudio) return
  42. }
  43. if (typeof target.audioTracks !== 'undefined') {
  44. if (target.audioTracks.length > 0) return
  45. }
  46. this.hasAudio = false
  47. }
  48. }
  49. }
  50. export default VideoAttachment