2012-01-11 27 views
0

我正在爲iOS 4.3及更高版本編寫應用程序,並使用automatic reference counting。我有一個使用AVPlayer播放的視頻,並希望在達到給定的CMTime時能夠暫停播放此視頻。我正在使用addBoundaryTimeObserverForTimes並在block內暫停AVPlayer。它的工作原理,但我收到的錯誤:在給定CMTime處暫停AVPlayer

Capturing 'self' strongly in this block is likely to lead to a retain cycle 

我的代碼:

timeObserver = [player addBoundaryTimeObserverForTimes:endTime //An array of one NSValue representing a CMTime 
               queue:NULL 
              usingBlock:^{ 
                  [player pause]; 
                 }]; 

我不能工作了這樣做的正確的方式將是任何幫助,非常感謝。

謝謝!

回答

0

您將不得不使用__weak存儲裝飾器。
例如把它放在你的分組代碼之前:

__weak MYClass* blockSelf = self; 

並使用blockSelf代替自己在你的塊內。

更新
就在這裏發現了這個優秀的答案在SO: https://stackoverflow.com/a/7854315/100848

+0

感謝weichsel。我不確定你的答案是否適用於我的情況...我可以在iOS 4.3中使用__weak嗎?無論如何,這是你提供的鏈接涵蓋,所以謝謝你! – Simple99 2012-01-18 11:09:48