0

I'm writing an app for iOS 4.3 and above and using automatic reference counting. I have a video which is played using an AVPlayer and would like to be able to pause this video when a given CMTime is reached. I am currently using addBoundaryTimeObserverForTimes and pausing the AVPlayer inside the block which is called. It works but I receive the error:

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

My code:

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

I can't work out the correct way of doing this and would be very grateful for any help.

Thank you!

Simple99
  • 1,038
  • 11
  • 20

1 Answers1

0

You'll have to use the __weak storage decorator.
e.g. put this before your block code:

__weak MYClass* blockSelf = self;

and use blockSelf instead of self inside your block.

Update
Just found this excellent answer here on SO: https://stackoverflow.com/a/7854315/100848

Community
  • 1
  • 1
Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112
  • Thanks weichsel. I'm not sure your answer would work in my case... Can I use __weak with iOS 4.3? Anyway that is covered in the link you provided so thank you! – Simple99 Jan 18 '12 at 11:09