Well i’m designing an iPhone app which will play video locally. When I click the button in the simulator it plays perfectly but when it stops or when I end it manually it crashed and keeps giving me that problem.. I tried clean, build, analyse and run again but still the same. Any help?
My code is that:
MoviePlayerViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MoviePlayerViewController : UIViewController {
}
-(IBAction)playMovie:(id)sender;
@end
and the main bit in MoviePlayerViewController.m
- (IBAction)playMovie:(id)sender {
NSString *movpath = [[NSBundle mainBundle] pathForResource:@"think" ofType:@"mp4"];
MPMoviePlayerViewController *mpviewController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.view addSubview:mpviewController.view];
MPMoviePlayerController *mp = [mpviewController moviePlayer];
[mp prepareToPlay];
mp.scalingMode=MPMovieScalingModeAspectFill;
[[mpviewController moviePlayer] play];
}
- (void)playbackFinishedCallback:(NSNotification *)notification {
MPMoviePlayerViewController *mpviewController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mpviewController];
[mpviewController.view removeFromSuperview];
[mpviewController release];
}
Have you tried making the movie player controller na ivar
Then you can do something like so in the implementation file