简体   繁体   English

Iphone mpmediaplayerController,用户按下完成后无法重新启动视频

[英]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.

相关问题 如何通过iPhone中的MPMediaPlayerController播放视频截图? - How to take a screenshot from an video playing through MPMediaPlayerController in iPhone? iPhone SDK 4.0上的MPMediaPlayerController - MPMediaPlayerController on iPhone SDK 4.0 在用户按下快照按钮之前,如何检索iPhone摄像机或视频图像? - How do I retrieve iPhone camera or video images before the user presses the snapshot button? 用户按下iPhone上的“保持”按钮后,如何保持音乐播放? - How do I keep music playing after the user presses the hold button on the iPhone? MPMediaPlayerController永久隐藏用户界面元素 - MPMediaPlayerController turn hide user interface elements permanently 当用户按下iPhone上的主页按钮时,如何在文本文件中保存数据? - How to save data in a text file as the user presses the home button on iPhone? 在iPhone锁定且用户按下电源按钮时编程背景行为 - Programming background behavior when iPhone is locked and user presses power button 当用户在iPhone上按下该按钮时,在UIButton上更改图像 - Changing image on UIButton when user presses that button on an iPhone 安装或升级应用程序后重新启动iPhone - Restart iPhone after installing or upgrading an app 在iPhone上拨打电话后自动重新启动WebApp - Automatically Restart WebApp after a phone call on an iPhone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM