Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top