[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

//
// VideoAttachmentCollectionViewCell.swift
// elpha-ios
//
// Created by Dwayne Harris on 11/29/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import AVFoundation
import AVKit
import UIKit
class VideoAttachmentCollectionViewCell: UICollectionViewCell {
var attachment: AttachmentMO?
var player: AVQueuePlayer!
var playerLayer: AVPlayerLayer!
var playerLooper: AVPlayerLooper?
override func awakeFromNib() {
super.awakeFromNib()
player = AVQueuePlayer()
player.preventsDisplaySleepDuringVideoPlayback = false
player.usesExternalPlaybackWhileExternalScreenIsActive = false
player.isMuted = true
playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = .resizeAspectFill
}
func update(withAttachment attachment: AttachmentMO) {
self.attachment = attachment
layer.addSublayer(playerLayer)
playerLayer.frame = bounds
playerLooper = AVPlayerLooper(player: player!, templateItem: AVPlayerItem(url: attachment.url!))
if SettingsManager.automaticallyPlayGIFs {
player.play()
}
}
}