[英]Iphone mpmediaplayerController, unable to restart video after user presses done
I'm having trouble with Iphone's mediaplayercontroller.我在使用 Iphone 的媒体播放器控制器时遇到问题。
I'm able to play the video once, with no problems.我可以播放一次视频,没有任何问题。
When the user presses done, I close the mediaplayer, and move my user back to the previous screen.当用户按下完成时,我关闭媒体播放器,并将我的用户移回上一个屏幕。 (I'm using a navigation based application).
(我正在使用基于导航的应用程序)。
However, when I try to start the video again by pressing the play button, the mediaplayercontroller no longer works correctly.但是,当我尝试通过按播放按钮再次开始播放视频时,媒体播放器控制器不再正常工作。
All I get is a black screen.我得到的只是黑屏。 No video, no sounds.
没有视频,没有声音。
I've already released the previous mediaplayper controller after getting the MPMoviePlayerPlaybackDidFinishNotification or the MPMoviePlayerDidExitFullscreenNotification.在获得 MPMoviePlayerPlaybackDidFinishNotification 或 MPMoviePlayerDidExitFullscreenNotification 后,我已经发布了之前的媒体播放器 controller。
Any advice would be greatly appreciated.任何建议将不胜感激。
More Info------- Here is a snippet of my code:更多信息-------这是我的代码片段:
- (void) viewDidAppear:(BOOL)animated
{
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayerController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil]; // This is to deal with the user pressing the done button.
[moviePlayerController setFullscreen:YES];
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"movie playback ended");
int reason = [[[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if(reason == MPMovieFinishReasonPlaybackEnded)
NSLog(@"Reason: MPMovieFinishReasonPlaybackEnded");
else if(reason == MPMovieFinishReasonPlaybackError)
NSLog(@"Reason: MPMovieFinishReasonPlaybackError");
else if(reason == MPMovieFinishReasonUserExited)
NSLog(@"Reason: MPMovieFinishReasonUserExited");
else
NSLog(@"Reason: %d", reason);
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[moviePlayerController.view removeFromSuperview];
moviePlayerController.initialPlaybackTime = -1;
[moviePlayerController pause];
[moviePlayerController stop];
[moviePlayerController release];
moviePlayerController = nil;
[[self navigationController] popViewControllerAnimated:YES];
}
-(void)videoFile:(NSString *)moviepath
{
//[tools setHidden:YES];
// bi3.enabled=NO;
// Register to receive a notification when the movie scaling mode has changed.
//NSString *moviePath = [bundle pathForResource:@"video" ofType:@"mp4"];
NSURL *movieURL1 = [[NSURL fileURLWithPath:moviepath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL1];
[theMovie setControlStyle:MPMovieControlStyleFullscreen];
[theMovie play];
MPMoviePlayerViewController *moviePlayer11 = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL1];
[self presentMoviePlayerViewControllerAnimated:moviePlayer11]; // Override point for customization after app launch
// [navigationController.view addSubview:];
//[self.view addSubview:mpMCtr.view];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
bi3.enabled=YES;
[tools setHidden:NO];
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
// [player stop];
//[self.view removeFromSuperview];
[player.view removeFromSuperview];
[player autorelease];
}
- (void) moviePlayBackDidFinish:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
//[mpMCtr stop];
[theMovie.view removeFromSuperview];
[videoTable removeFromSuperview];
//[self.navigationController popViewControllerAnimated:YES];
}
-(void)videoClick:(id)sender
{
bi3.enabled=NO;
path2 = [[NSBundle mainBundle] pathForResource:@"Interview" ofType:@"mp4" inDirectory:nil];
[self videoFile:path2];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.