使用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) 根据我的经验和研究,Android 和 iOS 的开箱即用 AV 播放器并不完全支持无缝/无缝循环。在其中任何一个上设置 isLooping=true 时总是存在明显的差距。我只能使用 SoundPool 让它在 Android 上无缝工作,但这仅适用于小型声音文件,不适用于大型 mp3。
目前,我编写了一个适用于 iOS 的解决方案,但奇怪的是它不适用于 Android。我猜他们至少应该保持一致?
另外,我很感兴趣是否有人可以帮助解决这个古老的问题,即在用户没有注意到间隙的情况下,以最有效的方式解决循环声音的问题。这个交叉推子的想法是开箱即用的,也许有人可以帮助改进它。我还在世博论坛上展开了讨论,如果有任何消息,我会在这里更新。
这是回购协议: https: //github.com/happyruss/expo-fader-loop
任何有关解决问题的建议都很棒。对于尝试react-native/expo的人来说,这也是一个有趣的简单项目