2

我正在使用下面的代码循环playerItem一个AVQueuePlayer

-(void) init {
    _soundPlayer = [ [ AVQueuePlayer alloc ] init ];
    [ _soundPlayer addObserver: self forKeyPath: @"status" options: NSKeyValueObservingOptionNew context: NULL ];
    [ [ NSNotificationCenter defaultCenter ] addObserver: self selector: @selector ( playerItemDidReachEnd: ) name: AVPlayerItemDidPlayToEndTimeNotification object: nil ];
    [ [ NSNotificationCenter defaultCenter ] postNotificationName: AVPlayerItemDidPlayToEndTimeNotification object: nil ];
}

- ( void ) observeValueForKeyPath: ( NSString * ) keyPath ofObject: ( AVPlayer * ) object change: ( NSDictionary * ) change context: ( void * ) context {
if ( _soundPlayer.status == AVPlayerStatusReadyToPlay )
    [ _soundPlayer play ];
}

- ( void ) playerItemDidReachEnd: ( NSNotification * ) notification {
    AVPlayerItem *playerItem = [ [ AVPlayerItem alloc ] initWithURL: [ NSURL fileURLWithPath: _playerItemFilePath ] ];
    [ _soundPlayer insertItem: playerItem afterItem: nil ];
    [ playerItem release ];
}

它在模拟器上工作正常,即使仪器表明泄漏类似于AudioToolbox SimAggregateDevice::SimAggregateDevice(__CFString const*, __CFString const*, long&),人们说这只是一些“帧泄漏”,在设备上会很好,但是当我在设备上运行它时,仪器没有显示泄漏,而是崩溃......我想念什么吗?感谢是否有人可以帮助我。

有时 playerItem 会在线流文件,所以不能使用AVAudioPlayer


最后,我发现是因为_playerItemFilePath. 已经不存在了,需要保留NSStringreturn by NSBundle'smethod 。pathForResource但我仍然想知道为什么它可以在模拟器上运行。毕竟泄漏audioToolbox也是固定的,所以任何人遇到有人提到的“框架泄漏”可能需要再次查看代码。它会因为一些小错误而出现。

4

0 回答 0