【问题标题】:AVPlayer does not retain AVPlayerItemAVPlayer 不保留 AVPlayerItem
【发布时间】:2012-04-09 17:18:15
【问题描述】:

有人知道为什么这段代码会在发布池中的某个地方崩溃(在调用“eject”之后)吗? 我在 AVPlayer 类参考中看到“currentItem”属性未声明为“保留”http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009530-CH1-SW21

这是 AVPlayer 类中的错误还是我应该将其保留在其他地方?

谢谢!

- (void) viewDidLoad {
    NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
    playerItem = [[AVPlayerItem alloc] initWithURL:url];
    player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
}

- (IBAction) eject {
    [player release];
    [playerItem release];
}

【问题讨论】:

    标签: ios4 retain avplayer


    【解决方案1】:

    我通常用它来设置播放器:

    if (!self.player) {
        player = [[AVPlayer alloc] init];
        }
    
        [self.player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:videoURL]];
    

    【讨论】:

    • 感谢您的回复。在释放播放器控制器本身之前,我终于通过从其父视图中删除播放器控制器(包含 AVPlayer)成功地释放了。
    【解决方案2】:

    我相信 AVPlayer 在 initWithPlayerItem: 函数中保留了 AVPlayerItem,因此您的 AVPlayerItem 可能会泄漏内存。 "currentItem" 是只读属性,不应是仅用于可写属性的 "retain"。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多