MPMoviePlayerViewController repeatMode not working? - iphone

I have a problem with MPMoviePlayerViewController and it's property repeatMode. It's stated that setting it to a MPMovieRepeatModeOne value will cause player to repeat playback. I use following code to play video in a loop but it just stops after the end.
MPMoviePlayerViewController *mpViewController =[[MPMoviePlayerViewController alloc] init];
mpViewController.moviePlayer.contentURL= movieURL;
self.aPlayer=mpViewController;
self.aPlayer.moviePlayer.repeatMode=MPMovieRepeatModeOne;

mpViewController.repeatMode=MPMovieRepeatModeOne;
worked for me but I did not have the url line or the self.'s
My next line after the above was [mpViewController play];

Remove this line
[self.aPlayer.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
and put:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidChangeState:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.player];
and implement
- (void)moviePlayerDidChangeState:(NSNotification *)note
{
MPMoviePlaybackState playbackState = [self.player playbackState];
if(playbackState==MPMoviePlaybackStateStopped ||playbackState==MPMoviePlaybackStatePaused || playbackState==MPMoviePlaybackStateInterrupted)
{
if (note.object == self.player) {
NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[self.player play];
}
}
}
}

Related

How to get done button action in Movie Player when loading in webView?

I am new to Iphone and trying to play video in webView. So, in that i need to have the done button action. Pls help me out.
If the video is played in UIWebView then you can access when the video is played and when Done button is pressed using the following code along with the code you have used to load url in webview
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
And it can be accessed through
BOOL isVideoInFullScreenMode;//Temperory added here.. must be in .h file or at teh top if required
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
isVideoInFullScreenMode = YES;
}
-(void)videoPlayFinished:(NSNotification *)notification{
//Your stuffs here
isVideoInFullScreenMode = NO;
}
Finally i found solution for Done button action...This logic is working for both ipad & iphone also..
I solved this prob by using UIGestureRecognizer.
Here is my code.
firstly i am adding notification for EnterFullScreen by using
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
Now in youTubeStarted method i added this Code..
-(void)youTubeStarted:(NSNotification *)notification{
if (!tapRecognizer1) {
tapRecognizer1 = [[UITapGestureRecognizer alloc] init];
tapRecognizer1.delegate = self;
[tapRecognizer1 setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:tapRecognizer1];
}
}
This will add TapRecognizer to the movieplayer..
And now the following delegate method will check that it is done button or not
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog(#"%#",touch.description);
NSString *ViewName = touch.description ;
CGPoint location = [touch locationInView:touch.view];
NSLog(#"location x===%f , location y=== %f",location.x,location.y);
NSRange Check = [ViewName rangeOfString:#"UINavigationButton"];
NSRange checkFrameOfButton;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
checkFrameOfButton = [ViewName rangeOfString:#"frame = (7 7; 50 30)"];
if (checkFrameOfButton.length <= 0) {
checkFrameOfButton = [ViewName rangeOfString:#"frame = (7 7; 51 30)"];
}
}
else {
checkFrameOfButton = [ViewName rangeOfString:#"frame = (5 7; 48 30)"];
if (Check.length<=0) {
Check = [ViewName rangeOfString:#"UIView"];
}
}
if (location.y<40 && location.x<85 && Check.length>0 && checkFrameOfButton.length>0) {
[self endplaying];
}
return YES;
}
Now in endplaying method you can do what you want...

MPMoviePlayerPlaybackDidFinishNotification being called again in iPhone 4.3 simulator when setting contentURL

NOTE: See the updates at the bottom.
I have an application to play videos one by one from a list. So, to test this functionality, I created a simple application with only one view controller. I referenced this blog before implementing this view controller. The view controller is named TNViewController and its implementation is as follows:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface TNViewController : UIViewController {
#private
NSMutableArray *_videoArray;
int _currentVideo;
MPMoviePlayerController *_moviePlayer;
NSURL *_movieUrl;
}
#end
Its implementation is:
#import "TNViewController.h"
#implementation TNViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[self.view setFrame:CGRectMake(0, 0, 480, 320)];
[self initVideos];
[self initPlayer];
}
- (void) initVideos {
_videoArray = [[NSMutableArray alloc] init];
NSString *path = [[NSBundle mainBundle] pathForResource:#"sintel_trailer" ofType:#"mp4" inDirectory:nil];
[_videoArray addObject:path];
path = [[NSBundle mainBundle] pathForResource:#"elephants_dream_trailer" ofType:#"mp4" inDirectory:nil];
[_videoArray addObject:path];
path = [[NSBundle mainBundle] pathForResource:#"big_buck_bunny_trailer" ofType:#"mp4" inDirectory:nil];
[_videoArray addObject:path];
_currentVideo = -1;
}
- (NSString*) nextVideo {
_currentVideo++;
if (_currentVideo >= _videoArray.count) {
_currentVideo = 0;
}
return [_videoArray objectAtIndex:_currentVideo];
}
- (void) initPlayer {
_moviePlayer = [[MPMoviePlayerController alloc]init];
[self readyPlayer];
[self.view addSubview:_moviePlayer.view];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
}
- (void) readyPlayer {
_movieUrl = [NSURL fileURLWithPath:[self nextVideo]];
[_movieUrl retain];
_moviePlayer.contentURL = _movieUrl;
// For 3.2 devices and above
if ([_moviePlayer respondsToSelector:#selector(loadState)]) {
// Set movie player layout
[_moviePlayer setControlStyle:MPMovieControlStyleNone];
[_moviePlayer setFullscreen:YES];
// May help to reduce latency
[_moviePlayer prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
} else {
// Register to receive a notification when the movie is in memory and ready to play.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
}
}
/*---------------------------------------------------------------------------
* For 3.1.x devices
*--------------------------------------------------------------------------*/
- (void) moviePreloadDidFinish:(NSNotification*)notification {
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
// Play the movie
[_moviePlayer play];
}
/*---------------------------------------------------------------------------
* For 3.2 and 4.x devices
*--------------------------------------------------------------------------*/
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
NSLog(#"moviePlayerLoadStateChanged");
// Unless state is unknown, start playback
if ([_moviePlayer loadState] != MPMovieLoadStateUnknown) {
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
// Set frame of movie player
[[_moviePlayer view] setFrame:CGRectMake(0, 0, 480, 320)];
// Play the movie
[_moviePlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSLog(#"playback finished...");
NSLog(#"End Playback Time: %f", _moviePlayer.endPlaybackTime);
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
NSLog(#"Reason: movie finished playing");
}else if (reason == MPMovieFinishReasonUserExited) {
NSLog(#"Reason: user hit done button");
}else if (reason == MPMovieFinishReasonPlaybackError) {
NSLog(#"Reason: error");
}
[self playNextVideo];
}
- (void) playNextVideo {
NSString *filePath = [self nextVideo];
[_movieUrl release];
_movieUrl = [NSURL fileURLWithPath:filePath];
[_movieUrl retain];
_moviePlayer.contentURL = _movieUrl;
[_moviePlayer play];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void) dealloc {
[_moviePlayer release];
[_movieUrl release];
[_videoArray release];
[super dealloc];
}
#end
Now, my problem is that the notification MPMoviePlayerPlaybackDidFinishNotification is called twice. As you can see from the above code, I have registered for it only once in the viewDidLoad(in initPlayer called from viewDidLoad). Here is the log output:
2012-07-02 12:29:17.661 DemoApp[1191:ef03] moviePlayerLoadStateChanged
2012-07-02 12:30:11.470 DemoApp[1191:ef03] playback finished...
2012-07-02 12:30:11.471 DemoApp[1191:ef03] End Playback Time: -1.000000
2012-07-02 12:30:11.472 DemoApp[1191:ef03] Reason: movie finished playing
2012-07-02 12:30:11.474 DemoApp[1191:ef03] playback finished...
2012-07-02 12:30:11.475 DemoApp[1191:ef03] End Playback Time: -1.000000
2012-07-02 12:30:11.476 DemoApp[1191:ef03] Reason: movie finished playing
2012-07-02 12:31:03.821 DemoApp[1191:ef03] playback finished...
2012-07-02 12:31:03.822 DemoApp[1191:ef03] End Playback Time: -1.000000
2012-07-02 12:31:03.824 DemoApp[1191:ef03] Reason: movie finished playing
2012-07-02 12:31:03.826 DemoApp[1191:ef03] playback finished...
2012-07-02 12:31:03.827 DemoApp[1191:ef03] End Playback Time: -1.000000
2012-07-02 12:31:03.827 DemoApp[1191:ef03] Reason: movie finished playing
As you can see, the playback finished is called twice. This causes one video to be skipped from the queue. (In fact, in original project where the problem occures, nextVideo caches a video in advance from the server, and returns the path to the cached video, if it exists in the cache. Otherwise, it returns nil.). Here, first the sintel_trailer.mp4 is played. After it finishes playback, instead of elephants_dream_trailer.mp4, it plays big_buck_bunny_trailer.mp4. That is, it cycles plays the videos skipping on in between. So, what is causing the MPMoviePlayerPlaybackDidFinishNotification to invoke twice? I am working on this for two days, still no luck. Any idea?
UPDATE 1:
Currently I am using a switch in the callback moviePlayBackDidFinish: like below and is working:
if (!_playNextVideo) {
_playNextVideo = YES;
return;
}
_playNextVideo = NO;
// code to play video....
But still I would like to know what causes the callback being called twice. I feel the current solution of switch like a hack, and like to remove it.
UPDATE 2:
Until now, I have been trying this with iPhone 4.3 simulator. But, when I tried the same program with iPhone 5.0 simulator and iPhone 5.1 simulator, it works without any problem. That is, only one callback is being sent after movie finished playing. And that renders my little hack(on update 1) useless (it solves the problem in 4.3 but creates problem in 5.0 and 5.1). I am using Xcode 4.3.2 running on MacOSX Lion - 10.7.4. Do you have any idea on how to solve this problem? Why two callbacks on 4.3?
UPDATE 3:
I pinpoint to the line causes problem. It is in playNextVideo method. The line causes problem is _moviePlayer.contentURL = _movieUrl;. Changing it in the first callback causes, the MPMoviePlayerPlaybackDidFinishNotification to be sent again. But, it happens only in iPhone 4.3 simulator. Any idea?
UPDATE 4:
Still, I haven't got any idea on this weird behavior. So, I am now using a time trick like the one in UPDATE 1 as follows on moviePlayBackDidFinish:
NSTimeInterval currentCallback = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval difference = currentCallback - _lastCallback;
_lastCallback = currentCallback;
if (difference < 5.0) {
return;
}
// code to play video....
I had the same problem. and solved it this way:
I created a new method to skip a video
- (void) skipVideo {
    [_moviePlayer stop];
}
Stopping the player in skipVideo will cause a MPMovieFinishReasonPlaybackEnded notification (in simulator and on device). When setting contentUrl of player now, no other MPMovieFinishReasonPlaybackEnded notification is caused, so moviePlayBackDidFinish is called only once;
Before playing next video (in playNextVideo) you have to call
[_moviePlayer prepareToPlay];
That works fine for me!
You can create new player for next track:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: _movieUrl];
if (player)
{
[self setMoviePlayer:player];
}
[self.moviePlayer play];
Instead of
self.moviePlayer.contentURL = _movieUrl;
Notification MPMoviePlayerPlaybackDidFinishNotification will called once.

How to play another video in the same MPMoviePlayerController?

*I'm creating an iPhone app where we can watch videos...
I,ve been making my own controls so I want to implement the next, back buttons, I can show theme so for the UI everything is ok the problem is to restart the MoviePlayer with another content...
Any idea???
I could use the same configuration when the playback did finish, I mean... If the video ends playing to start playing another one...
I've tried to set contentUrl but it trows an exception:
2012-04-17 11:37:41.198 NexTest2[8218:11f03] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 11.5]'
viewController.m
- (void)viewDidLoad{
[super viewDidLoad];
fileURL = [NSURL URLWithString:urlString];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[moviePlayerController setShouldAutoplay:YES];
[self addObservers];
/* Inset the movie frame in the parent view frame. */
CGRect viewInsetRect = CGRectInset ([self.view bounds],0.0, 0.0 );
[[moviePlayerController view] setFrame: viewInsetRect ];
[self.view addSubview:moviePlayerController.view];
[self resizeControlViews];
}
then in resizeControlViews I have this, cause I'm using these two views like controls:
-(void)resizeControlViews{
CGRect barFrame = self.controlBarView.frame;
barFrame.origin.x = round((moviePlayerController.view.frame.size.width - barFrame.size.width) / 2.0);
barFrame.origin.y = round((moviePlayerController.view.frame.size.height - barFrame.size.height)/10.0);
self.controlBarView.frame = barFrame;
[moviePlayerController.view addSubview:controlBarView];
CGRect playFrame = self.controlPlaybackView.frame;
playFrame.origin.x = round((moviePlayerController.view.frame.size.width - playFrame.size.width) / 2.0);
playFrame.origin.y = round((moviePlayerController.view.frame.size.height - playFrame.size.height)/1.1);
self.controlPlaybackView.frame = playFrame;
[moviePlayerController.view addSubview:controlPlaybackView];
}
Here everything is working fine, in one of these views there is a slider who controls the seeking, and in the other one are the play, next and back buttons.
I think maybe the problem is whit the UI components of these views...
I've added these observers to control the playback:
//Add the observers to the player
-(void)addObservers{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackStarted:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(setDurationLabel:) name:MPMovieDurationAvailableNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];
}
so to handle when the player is playing I use the MPMoviePlayerPlaybackStateDidChangeNotification with this selector:
//called when the playback state changes of state
- (void)playbackStarted:(NSNotification*)notification {
MPMoviePlayerController *player = notification.object;
if (player.playbackState == MPMoviePlaybackStatePlaying) {
[self timerRunning];
}
}
and if the player is "playing" I monitor it with this method:
-(void)timerRunning{
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)];
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {
[self performSelector:#selector(timerRunning) withObject:nil afterDelay:0.5];
}
}
so Maybe here is the issue... but with a single video it works perfectly...
I've four where the mistake is... is while i'm monitoring in the line to set the value to the slider, but I really don't know why, I think it is cause when another video or stoping video it is still executed so the player has not duration or current playback what trows this exception... how could I to solve it... here is the mistake... maybe moving this code to another part...
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
Check your UI related code. You most likely are not properly checking the player status before getting and using content related properties from it.
Well finally it works fine... the setCurrentContentUrl works fine, the problem was my code so I solved it... I just validate that duration was different to 0...
Now I have a player with full custom controls :) cool :)
-(void)timerRunning{
if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)];
if (moviePlayerController.duration != 0) {
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
}
[self performSelector:#selector(timerRunning) withObject:nil afterDelay:0.5];
}
}
Thank you anyways

MPMoviePlayerController failing to stream .3gp video since iOS 4.3

I have an existing iPhone/iPad universal app that streamed video with the MPMoviePlayerController over wi-fi (mp4) and 3G Network (3gp). When iOS 4.3 was released our 4.3 devices can no longer play a 3gp video over 3G network. I tested a local 3gp file and that fails too, but works on a 3G phone running 4.2.x.
After debugging the view controller I see the MPMoviePlayerLoadStateDidChangeNotification notification is not being triggered when trying to play the 3gp file locally or streaming it via URL.
[APPDEL showStatusView: #"Please wait..."];
NSString * videoUrl = [[request.URL description] stringByReplacingOccurrencesOfString: #"idvideo:" withString: #"http:"];
DLog(#"Loading video %#", videoUrl);
_moviePlayer = [[IDMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString: videoUrl]];
_moviePlayer.view.backgroundColor = [UIColor clearColor];
_moviePlayer.allowsAirPlay = YES;
_moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if ([_moviePlayer respondsToSelector:#selector(loadState)]) {
// May help to reduce latency
[_moviePlayer prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:_moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerPreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:_moviePlayer];
//[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(moviePlayerTimerUp:) userInfo:nil repeats:NO];
}
else {
// Register to receive a notification when the movie is in memory and ready to play.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(onMovieDone:) name: MPMoviePlayerPlaybackDidFinishNotification object: nil];
if ([_moviePlayer respondsToSelector: #selector(view)]) {
[self.view addSubview: _moviePlayer.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
else {
_moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
}
_moviePlayer.view.frame = _webView.frame;
}
[_moviePlayer play];
The first condition for the loadState is always hit. For the 3gp file the code will never reach the moviePlayerLoadStateChanged selector method which hides an indicator/status view and creates other fullscreen/orientation notifications. The indicator/status view will just remain up & spinning. Within debugger I can see the onMovieDone selector method gets triggered far sooner than the video would of really of finished.
Confused.
This my answer in regards with playing .3gp file with iPhone .....I have successfully played .3gp file with iphone sdk with using MpMoviePlayerController and my answer link is:
Link: https://stackoverflow.com/a/13088808/1092219
hope you will got help from my answer.........!! :))))))

MPMoviePlayerController plays after canceling in 3.1.2

I have encountered a problem with the MPMoviePlayerController in 3.1.2.
If I cancel the player while it is still loading, the player closes. However, the video starts playing a few moments later in the background. The only ways to stop it are to play another video or close the app. This seems to work fine in 3.2+.
Here's what I'm doing:
- (void)loadMoviePlayer
{
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
if ([NSClassFromString(#"MPMoviePlayerController") instancesRespondToSelector:#selector(view)])
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
// running iOS 3.2 or better
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"http://www.mysite.com/myvideo.m3u8"]];
[moviePlayer.view setBackgroundColor:[UIColor blackColor]];
[moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
// [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleNone];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer.moviePlayer prepareToPlay];
[moviePlayer.moviePlayer play];
#endif
}
else
{
MPMoviePlayerController *mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://www.mysite.com/myvideo.m3u8"]];
mMPPlayer.scalingMode=MPMovieScalingModeFill;
mMPPlayer.backgroundColor=[UIColor blackColor];
[mMPPlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];
}
I added moviePlayBackDidFinish this morning. It gets called when I hit cancel, but dismissModalViewControllerAnimated doesn't seem to do anything. I also tried removeFromSuperView, but my player will not respond.
So, how can I make sure the player does not play after hitting "cancel"?
Thanks in advance.
You may have come across an old bug in MPMoviePlayerController. Back in the days, we actually had to play an almost empty (black, silence) M4V after playing proper content to be sure the player does not attempt to continue playback in the background when stopping at certain stages. That bug manifests in audible sound but no picture of the aborted/stopped video.
There are however a few more things worth trying when stopping (assuming your instance of MPMoviePlayerController is called moviePlayer);
set the current playback position to the complete movie duration moviePlayer.currentPlaybackTime = moviePlayer.duration;
send another stop within your notification handler [moviePlayer stop];
In my case, I found that setting the following line would eventually stop the movie player from playing:
moviePlayer.contentURL = nil;
(with moviePlayer your instance of MPMoviePlayerController).