[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

6 years ago
  1. //
  2. // VideoAttachmentCollectionViewCell.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 11/29/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import AVFoundation
  9. import AVKit
  10. import UIKit
  11. class VideoAttachmentCollectionViewCell: UICollectionViewCell {
  12. var attachment: AttachmentMO?
  13. var player: AVQueuePlayer!
  14. var playerLayer: AVPlayerLayer!
  15. var playerLooper: AVPlayerLooper?
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18. player = AVQueuePlayer()
  19. player.preventsDisplaySleepDuringVideoPlayback = false
  20. player.usesExternalPlaybackWhileExternalScreenIsActive = false
  21. player.isMuted = true
  22. playerLayer = AVPlayerLayer(player: player)
  23. playerLayer.videoGravity = .resizeAspectFill
  24. }
  25. func update(withAttachment attachment: AttachmentMO) {
  26. self.attachment = attachment
  27. layer.addSublayer(playerLayer)
  28. playerLayer.frame = bounds
  29. playerLooper = AVPlayerLooper(player: player!, templateItem: AVPlayerItem(url: attachment.url!))
  30. if SettingsManager.automaticallyPlayGIFs {
  31. player.play()
  32. }
  33. }
  34. }