如果我点击"完成"按钮关闭MPMoviePlayerViewController在完成与url的连接之前(BEFORE显示视频),它仍将在后端工作。一段时间后(连接完成时)会听到视频的声音。
有什么问题?
我的代码:
- (void) showVideo:(NSString *)vurl
{
NSDictionary *videos;
videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:vurl]];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[videos objectForKey:@"medium"]]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerDidExitFullscreen:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
[mp.moviePlayer prepareToPlay];
[_window.rootViewController.view addSubview:mp.view];
[mp release];
}
通知代码:
- moviePlayerDidExitFullscreen:(NSNotification *)theNotification {
ImageTargetsAppDelegate *appDelegate = (ImageTargetsAppDelegate *)[[UIApplication sharedApplication] delegate];
MPMoviePlayerViewController *player = [theNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player.view removeFromSuperview];
[player.moviePlayer stop];
[player release];
}
如果我也在使用MPMoviePlayerController,问题也是一样的。我正在使用iOS 7.1。
谢谢,