views:

261

answers:

1

Hi there

I'm wondering if any of you have encountered similar problems and of course happened to find a proper or not so proper (but working) solution/workaround.

I'm using a MPMoviePlayerViewController and I'm trying to a add Swipe-Gesture Recognizers onto the MPMoviePlayerViewControllers view.

moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];
[moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[moviePlayerViewController.moviePlayer setScalingMode: MPMovieScalingModeAspectFit];

UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousChannel)];
swipeGestureRight.direction = UISwipeGestureRecognizerDirectionRight;
[myMoviePlayerViewController.view addGestureRecognizer:swipeGestureRight];
[self.view addSubview:moviePlayerViewController.view];

anyway, it "kind of works" but when I'm testing the whole thing by doing the gesture on top of the running movie player instance (both, either in simulator or on device) the app crashes and the console states

** -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0xf074bb0

does any of you have an idea on that topic?

A: 

It seems that iOS is freeing your MPMoviePlayerViewController object and then sending a message to it later. I would suggest making the instance a member of your class, and then instantiating a property for it, eg:

@property (nonatomic, retain) MPMoviePlayerViewController *moviePlayerViewController;

...along with the corresponding @synthesize declaration your class' implementation file. When allocating your object, you should then do:

  self.moviePlayerController = [[[MPMoviePlayerViewController alloc] initWithContentURL:@"yourUrl"] autorelease];

And finally, release the object by setting it to nil in your dealloc method.

Nik Reiman