使用AVPlayerLooper无限循环播放视频时,我的应用程序崩溃并显示“由于内存问题而终止” 。该问题仅发生在较旧的设备上(在 iPhone 6S 和更新版本上不会发生)并且循环非常短(短于 1 秒)。
我试过使用 AVPlayer 并观察AVPlayerItemDidPlayToEndTime,然后试图手动开始,但是这个解决方案会导致每个循环之间出现短暂的中断/打嗝,这导致了我特定需求的计时问题。在呼叫之前暂停seek(to: CMTime.zero)并不能解决问题。
这是我的 Looper 课程:
class Looper: NSObject {
private var playerItem: AVPlayerItem!
private var player: AVQueuePlayer!
private let playerLayer = AVPlayerLayer()
private var playerLooper: AVPlayerLooper!
private var isPaused: Bool = false {
didSet {
isPaused ? player.pause() : player.play()
}
}
weak var delegate: LooperDelegate?
required init(videoURL: URL) {
super.init()
let asset = AVURLAsset(url: videoURL, options: ["AVURLAssetPreferPreciseDurationAndTimingKey" : true])
playerItem = AVPlayerItem(asset: asset)
player …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的UICollectionView:
这是三种不同的情况.浅灰色显示集合视图的边框,深灰色显示单元格.我已经将min spacing和section insets设置为0.但是我仍然得到这些不需要的插入内容,并且它似乎只有在有超过1个单元格时才会发生.
我像这样计算项目大小:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
guard let item = place?.publicTransports?[indexPath.row] else {
return CGSize.zero
}
var lines = ""
for (i, line) in item.lines.enumerate() {
lines.appendContentsOf(line)
if i != item.lines.count - 1 {
lines.appendContentsOf(", ")
}
}
let linesString = lines as NSString
return CGSize(width: linesString.sizeWithAttributes(nil).width + 35 + 20, height: collectionView.bounds.height/2)
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?