简体   繁体   English

通知似乎未从MPMoviePlayerController触发

[英]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. 我正在尝试获取一个简单的视频,以便在具有iOS 4.3的iPhone上播放,并且遇到解雇视频播放器的问题。 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 addSubview:self.mpvc.view];

Are you sure your self.mpvc.moviePlayer is a valid object which is sending the notification. 您确定您的self.mpvc.movi​​ePlayer是发送通知的有效对象。

Are you sure you MPMoviePlayerPlaybackDidFinishNotification MPMoviePlayerDidExitFullscreenNotification MPMoviePlayerWillExitFullscreenNotification same notification name.. 您确定您的MPMoviePlayerPlaybackDidFinishNotification MPMoviePlayerDidExitFullscreenNotification MPMoviePlayerWillExitFullscreenNotification相同的通知名称。

Here is the sample code/example of NSNotification 这是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 . 对象参数应该是self.mpvc而不是self.mpvc.moviePlayer So try to replace your 3 lines with these: 因此,尝试用以下内容替换您的3行:

[[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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM