首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVPlayer不保留AVPlayerItem

AVPlayer不保留AVPlayerItem
EN

Stack Overflow用户
提问于 2010-12-07 19:02:00
回答 2查看 4.2K关注 0票数 2

有人知道为什么这段代码会在发布池中的某个地方崩溃(在调用'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类中的一个bug,还是应该将它保留在其他地方?

谢谢!

代码语言:javascript
复制
- (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];
}
EN

回答 2

Stack Overflow用户

发布于 2011-01-20 03:16:36

我通常使用下面的代码来设置播放器:

代码语言:javascript
复制
if (!self.player) {
    player = [[AVPlayer alloc] init];
    }

    [self.player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:videoURL]];
票数 2
EN

Stack Overflow用户

发布于 2012-04-09 17:18:15

我相信AVPlayer在initWithPlayerItem: function中保留了AVPlayerItem,所以您的AVPlayerItem可能会泄漏内存。"currentItem“是只读属性,不应该是"retain”,因为它只适用于可写属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4375919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档