2010-12-07 69 views
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-SW21AVPlayer不保留AVPlayerItem

這是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

我通常使用此設置一個球員:

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

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

感謝您的回覆。在釋放播放器控制器之前,我最終通過從其超級視圖中移除播放器控制器(包含AVPlayer)而成功釋放了沒有任何崩潰的聲音。 – 2011-01-24 09:54:01

0

我相信AVPlayer保留AVPlayerItem在initWithPlayerItem:功能,所以你可能與你的AVPlayerItem內存泄漏。 「currentItem」是隻讀屬性,不應該是僅用於可寫屬性的「保留」。