AVPlayer不保留AVPlayerItem

时间:2010-12-07 11:02:00

标签: ios4 retain avplayer

有人知道为什么这个代码在发布池中的某个地方崩溃(在调用'eject'之后)? 我在AVPlayer类引用中看到'currentItem'属性未声明为'retain'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];
}

2 个答案:

答案 0 :(得分:2)

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

if (!self.player) {
    player = [[AVPlayer alloc] init];
    }

    [self.player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:videoURL]];

答案 1 :(得分:0)

我相信AVPlayer会在initWithPlayerItem:function中保留AVPlayerItem,因此您可能会使用AVPlayerItem泄漏内存。 “currentItem”是readonly属性,不应该是“retain”,它只适用于可写属性。