小编Tom*_*ran的帖子

使用 AVPlayerLooper 时“由于内存问题而终止”

使用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)

ios avplayer swift avplayerlooper

6
推荐指数
0
解决办法
199
查看次数

左对齐一个UICollectionView

我有一个像这样的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)

有什么建议?

ios uicollectionview swift

1
推荐指数
1
解决办法
4308
查看次数

标签 统计

ios ×2

swift ×2

avplayer ×1

avplayerlooper ×1

uicollectionview ×1