Error Message: MPMoviePlayerController instance is already playing - iphone

In my app I am playing video(s) that are in the app, using the standard MPMoviePlayerController class.
The first time around around this works great, however after watching 1 video if you try and watch something else the app crashes on MPMoviePlayerController's play method with the error:
*** Terminating app due to uncaught exception 'MPMoviePlayerControllerPlaybackException', reason: 'MPMoviePlayerController instance is already playing'
I can not figure out why this is happening.
I have VERY similar code in another app and I don't get this error.
I am compiling for the device - 2.0 and running it on an iPhone with firmware 2.2.1.
This is the code I have:
#synthesize movieURL;
- (void) setMovieAndPlay
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
moviePath = [[[paths lastObject] stringByAppendingPathComponent:movieURL] retain];
[self playVideoWithURL:[NSURL fileURLWithPath:moviePath]];
}
-(void)playMovieAtURL:(NSURL*)theURL
{
MPMoviePlayerController *mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
mMoviePlayer.scalingMode = MPMovieScalingModeAspectFill;
if ([defaults boolForKey:#"disableControls"])
{
mMoviePlayer.movieControlMode = MPMovieControlModeHidden;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mMoviePlayer];
[mMoviePlayer play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie release];
theMovie = nil;
NSDictionary *notiUserInfo = [notification userInfo];
if (notiUserInfo != nil)
{
NSError *errorInfo = [notiUserInfo objectForKey:#"error"];
if ([[errorInfo domain] isEqualToString:#"MediaPlayerErrorDomain"])
{
UIAlertView *notice = [[UIAlertView alloc] initWithTitle:#"Error" message:[errorInfo localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[notice show];
[notice release];
return;
}
}
if ([defaults boolForKey:#"autoRepeat"])
{
[self playMovieAtURL:[NSURL fileURLWithPath:moviePath]];
}
else
{
KFAppDelegate *appDelegate = (KFAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate endMovie];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
KFAppDelegate *appDelegate = (KFAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate endMovie];
}
What is even stranger is, if you look at the code, after the movie ends I check if the user has enable auto-repeat.
If they have, I just start the movie over again, and THIS WORKS.
However if they did not enable auto-repeat and leave this class and then try to watch another movie (or the same one) it gives that crash.
Does anyone know why this would be happening?
Am I doing something wrong?
Thanks!

Here's my solution. I had to make the next playback wait 1 second using NSTimer or I'd get the same audio-only problem everyone has been talking about. This is for 2.2.1.
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(playTrack) userInfo:nil repeats:NO];
}
- (void) playTrack {
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer release];
NSURL *nsUrl = [NSURL URLWithString:track.url];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:nsUrl];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer play];
}

I think in
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
// you should add this:
if (mMoviePlayer != nil) {
// free the old movie player
NSLog(#"releasing!");
[mMoviePlayer release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}

You will get this error only if your MPMoviePlayerController object has not been released and you are trying to play another movie.
Create an instance variable of MPMoviePlayerController and use that through out your code. So instead of
theMovie = [notification object];
[theMovie release];
theMovie = nil;
use an instance variable and use that in playMovieAtURL and playbackDidFinish methods. My problem was that the movie player object was not getting released and so I could not see the next video, only hear the audio playing.
Hopefully that'll help.

This seems to have been fixed in newer iOS versions.

Related

How to dismiss MPMoviePlayerController after stopping video

I have successfully stopped a video within 30 seconds. But I am not able to dismiss the MP MovieViewController and I want to stop activity for buffering. I have used this code.....
Video Play Code :
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Pungi" ofType:#"mp4"]];
self.movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.movie .controlStyle = MPMovieControlStyleEmbedded;
[ self.movie play];
[self.view addSubview:self.movie.view];
[self.movie setFullscreen:YES animated:YES];
self.movie.initialPlaybackTime = 0.5;
[NSTimer scheduledTimerWithTimeInterval:15.0
target:self
selector:#selector(stopVideo)
userInfo:nil
repeats:NO];
stopVideo :
[self.movie stop];
[self.movie.view removeFromSuperview];
[self.movie release];
Put your MPMoviePlayerController in a separate class and load it:
MoviePlayerViewController.h
#import <MediaPlayer/MediaPlayer.h>
#interface MoviePlayerViewController : UIViewController
#end
MoviePlayerViewController.m
#import "MoviePlayerViewController.h"
MPMoviePlayerViewController *movieController;
#interface MoviePlayerViewController ()
#end
#implementation MoviePlayerViewController
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(#"willEnterFullscreen");
}
- (void)enteredFullscreen:(NSNotification*)notification {
NSLog(#"enteredFullscreen");
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(#"willExitFullscreen");
}
- (void)exitedFullscreen:(NSNotification*)notification {
NSLog(#"exitedFullscreen");
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)playbackFinished:(NSNotification*)notification {
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
[self dismissModalViewControllerAnimated:YES];
break;
case MPMovieFinishReasonPlaybackError:
break;
case MPMovieFinishReasonUserExited:
[self dismissModalViewControllerAnimated:YES];
break;
default:
break;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(enteredFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSString *videoName = #"Videoname";
NSString *filepath = [[NSBundle mainBundle] pathForResource:videoName #"movietype"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[movieController.view setFrame:CGRectMake(0, -20, 320, 480)];
[self.view addSubview:movieController.view];
[movieController.moviePlayer play];
}
ViewController.m
MoviePlayerViewController *player = [[MoviePlayerViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:player animated:YES];
What it does:
MoviePlayerViewController is a custom class which loads an MPMoviePlayerController with a Video. in the viewDidLoad method (or wherever you want it) you LOAD the MoviePlayerViewController.
([self presentModalViewController:animated])....
This has the advantage, that your main class isn't overloaded with moviecrap/definitions and you can EASILY dismiss the MoviePlayerViewController when it is finished using Notifications to check wether it has stopped or not.
if it has stopped:
[self dismissModalViewControllerAnimated:YES];
Hope this Helps!
As code below shows, you should pause and set initialPlaybackTime to -1 before actual stop. This is one of tricky things that MPMoviePlayerController provides.
[_moviePlayerController pause];
if ([_moviePlayerController isKindOfClass:[MPMoviePlayerController class]]) {
((MPMoviePlayerController*)_moviePlayerController).initialPlaybackTime = -1;
}
[_moviePlayerController stop];
if ([_moviePlayerController isKindOfClass:[MPMoviePlayerController class]]) {
((MPMoviePlayerController*)_moviePlayerController).initialPlaybackTime = -1;
}
[_moviePlayerController.view removeFromSuperview];
You need to add notification observer in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerPlaybackDidFinishNotification:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
Then add the method:
- (void)moviePlayerPlaybackDidFinishNotification:(NSNotification*)notification
{
[self dismissMoviePlayerViewControllerAnimated];
}
Import the some headers in your header:
#import <MediaPlayer/MediaPlayer.h>
#import <MediaPlayer/MPMoviePlayerViewController.h>
You may also need to balance your "presentMoviePlayer" call with the dismiss somewhere:
[self dismissMoviePlayerViewControllerAnimated];
if you are finished with the resource early, you may be able to release it sooner by using NotificationManager to watch for MPMoviePlayerPlaybackDidFinishNotification.
and also
- (void)dealloc {
[movie release],
movie = nil;
[super dealloc];
}
try this.......
self.movie.initialPlaybackTime = -1;
[self.movie stop];
[self.movie release];

iphone ios xcode 4.2 - EXC_BAD_ACCESS signal

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];
}
There are few issues in the code, here are the fixes:
1> Remove [mpviewController release]; because it is created using a method which returns *autorelease* object.([notification object]). To release the mpviewController object declare it as instance variable and release it and make it nil.
if(mpviewController != nil)
{
[mpviewController release];
mpviewController = nil;
}
2> As you have declared mpviewController as instance variable, there is no need to access mpviewController variable via [notification object] because its not there as you have not supplied it when you add observer to notification center.
3> Replace following line of code:
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mpviewController];
with
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
Explaination: When you add observer you are not providing any object information but at the time of removal you
So now your code will become:
- (void)playbackFinishedCallback:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[mpviewController.view removeFromSuperview];
if(mpviewController != nil)
{
[mpviewController release];
mpviewController = nil;
}
}
Also, in - (void) dealloc of this controller you should write similar code for releasing mpviewController.
Thanks,
Have you tried making the movie player controller na ivar
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
#interface MoviePlayerViewController : UIViewController {
}
#property (nonatomic, retain) MPMoviePlayerViewController *mpviewController;
-(IBAction)playMovie:(id)sender;
#end
Then you can do something like so in the implementation file
#synthesize mpviewController;
- (IBAction)playMovie:(id)sender {
NSString *movpath = [[NSBundle mainBundle] pathForResource:#"think" ofType:#"mp4"];
MPMoviePlayerViewController *mpController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
self.mpviewController = mpController;
[mpController release];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.view addSubview:self.mpviewController.view];
MPMoviePlayerController *mp = [self.mpviewController moviePlayer];
[mp prepareToPlay];
mp.scalingMode=MPMovieScalingModeAspectFill;
[[self.mpviewController moviePlayer] play];
}
- (void)playbackFinishedCallback:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mpviewController];
[mpviewController.view removeFromSuperview];
}
- (void)viewDidUnload {
self.mpviewController = nil;
}
- (void)dealloc{
self.mpviewController = nil;
[super dealloc];
}

MPMoviePlayerViewController quits while playing the video

I am recording the video in my application. I am saving that video inside Documents directory. After taking the video if I try to play the video using the following code. The player opens and quits in one seconds. However if I Quit and then open my app fresh the video I took earlier is playing.
+ (void) playMovieAtURL: (NSURL*) theURL :(id)sender{
NSLog(#"playMovieAtURL");
//senderID = (id *)sender;
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
NSLog(#"> 3.2");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
if (mp)
{
// save the movie player object
//self.moviePlayerViewController = mp;
//[mp release];
[sender presentMoviePlayerViewControllerAnimated:mp];
//mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[mp.moviePlayer play];
}
[mp release];
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
NSLog(#"< 3.2");
MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: #selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
[theMovie release];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *aMoviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:aMoviePlayer];
// If the moviePlayer.view was added to the view, it needs to be removed
if ([aMoviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[aMoviePlayer.view removeFromSuperview];
}
}
This is the code I use for storing the video inside documents.
NSURL *videoURL = [imageInfo objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
self.itsVideoName = fileName;
[webData writeToFile:[NSString stringWithFormat:#"%#/%#",dataPath,fileName] atomically:TRUE];
I finally figured out the answer after few hours of searching. This is the code I am using now..
-(IBAction)playMovie:(NSString *) theURL
{
NSURL *fileURL = [NSURL fileURLWithPath:theURL];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
//After putting the following line the problem solved.
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
the code moviePlayerController.useApplicationAudioSession = NO; is used to solve this problem. I am not sure how this problem solved I guess I am using session for audio I guess that was causing problem to this.
Also the code which I originally posted was taking lots of memory like if I opened 2 video it cost 104 mb allocation for me. This new code was perfect and it is taking only less memory. Hope this will help for some one..
*NSURL fileURL = [NSURL fileURLWithPath:theURL];
should use NSURL *fileURL = [NSURL URLWithString:theURL];

Play 2 videos from url one after another

In my application i want to play 2 url videos one after another.
This is my code:
`- (void)viewDidLoad {
NSLog(#"viewDidLoad");
player = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
[super vieDidLoad];
}
- (NSURL *)movieURL {
return [NSURL URLWithString: #"https://s3.amazonaws.com/adplayer/colgate.mp4"];//First video url after this video complete.I want to play the next url video.
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
}
`
After one url video completed i want to play the next url video.
please anyone help me.
I have store the url's in array like this,
array=[[NSArray alloc] initWithObjects:#"https://s3.amazonaws.com/adplayer/colgate.mp4",#"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
Then how can i retrive the url in - (void) movieFinishedCallback:(NSNotification*) aNotification {
}method.please give me guidance in this.
I a have not tested it, but is should work, You might need it modify it little bit. At least, you now have an idea, how this can be done
-(void)viewDidLoad
{
[self initializPlayer];
}
static int i;
-(void)initializPlayer
{
if(i<=[arrMovieURL count])
i +=1;
else {
i = 0;
}
if(player)
{
[player release];
player = nil;
}
player = [[MPMoviePlayerController alloc] initWithContentURL:[arrMovieURL objectAtIndex:i]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
//calling again to play the next video
[self initializPlayer];
}

A problem with Media Player base on iOS4 and deploy iOS3

when Run on Device 3.1.2, why it also pass if(NSClassFromString(#"MPMoviePlayerViewController") != nil)
and do code of iOS4 then it will crash , how to fix this issues?
if(NSClassFromString(#"MPMoviePlayerViewController") != nil) {
// iOS 4 code
NSLog(#"MPMoviePlayerViewController");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:AppDelegate.PushLink]];
if (mp) {
// save the movie player object
self.theMovie4 = mp;
[mp release];
//Present
[self presentMoviePlayerViewControllerAnimated:self.theMovie4];
// Play the movie!
self.theMovie4.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self.theMovie4.moviePlayer play];
}
}
else {
//iOS 3 Code
AppDelegate = nil;
AppDelegate = [[UIApplication sharedApplication] delegate];
[AppDelegate ForceHideNavigationBar];
theMovie3 = nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:theMovie3];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie3];
// Register to receive a notification when the movie scaling mode has changed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieScalingModeDidChange:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:theMovie3];
theMovie3 = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:AppDelegate.PushLink]];
[theMovie3 play];
}
I am doing a very similar thing on my app which is using 4.0 as the base SDK and yet I am targeting iOS3 devices too. I had to check the OS version to properly provide the right code for the video playback. For example:
- (void) playMovieAtURL: (NSURL*) theURL {
NSLog(#"playMovieAtURL");
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
NSLog(#"> 3.2");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
if (mp)
{
// save the movie player object
//self.moviePlayerViewController = mp;
//[mp release];
[self presentMoviePlayerViewControllerAnimated:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mp.moviePlayer play];
[mp release];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
NSLog(#"< 3.2");
MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: #selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
}
Hope this helps!!
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSString *movpath = [[NSBundle mainBundle] pathForResource:#"splash" ofType:#"mp4"];
MPMoviePlayerViewController* mpviewController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
[window addSubview:mpviewController.view];
[window makeKeyAndVisible];
MPMoviePlayerController *mp = [mpviewController moviePlayer];
[mp prepareToPlay];
[[mpviewController moviePlayer] play];
This code will work in iOS4
It however does quit once the movie completes because you must create the method for the notification. Also you need to release the movie there so that you can catch the memory leak.