开发者

Notifications don't seem to be fired from MPMoviePlayerController

I'm trying to get a simple video to play on an iPhone with iOS 4.3 and am running in to issues with dismissing the video player. Below is the code I have set up ... I'm listening for three different notification events to help signal when the movie player and its parent view should exit, but none of those events seem to get fired. My callback method is never invoked.

NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"sample1" ofType:@"m4v"];
NSLog(@"Here is the movie path: %@", moviePath);
NSURL* movieUrl = [NSURL fileURLWithPath:moviePath];
NSLog(@"Will now try to play movie at the following url: %@", movieUrl);
self.mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpvc.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerDidExitFullscreenNotification object:self.mpvc.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerWillExitFullscreenNotification object:self.mpvc.moviePlayer];
[[self.mpvc moviePlayer] prepareToPlay];
[[self.mpvc moviePlayer] setShouldAutoplay:YES];
[[self.mpvc moviePlayer] setFullscreen:YES];

[self.mpvc.view setFrame: self.view.bounds];  // player's frame must match parent's
[self.view addSubv开发者_如何学运维iew:self.mpvc.view];


Are you sure your self.mpvc.moviePlayer is a valid object which is sending the notification.

Are you sure you MPMoviePlayerPlaybackDidFinishNotification MPMoviePlayerDidExitFullscreenNotification MPMoviePlayerWillExitFullscreenNotification same notification name..

Here is the sample code/example of NSNotification

[[NSNotificationCenter defaultCenter] addObserver:self 
   selector:@selector(manageHistory:) name:@"historyLoaded" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"historyLoaded" 
   object:nil userInfo:jsonReturn];

- (void) manageHistory: (NSNotification *) historyData{
     NSDictionary* _dict = historyData.userInfo;
     NSLog(@"Your information embedded to dictionary obj %@",_dict);
}


You probably did a mistake in registering the movie player callbacks. The object parameter should be self.mpvc instead of self.mpvc.moviePlayer. So try to replace your 3 lines with these:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpvc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerDidExitFullscreenNotification object:self.mpvc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerFinished:) name:MPMoviePlayerWillExitFullscreenNotification object:self.mpvc];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜