首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Iphone mpmediaplayerController,用户按下完成后无法重启视频

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

Stack Overflow用户
提问于 2011-07-09 11:17:29
回答 1查看 756关注 0票数 0

我的Iphone的媒体播放器控制器出了点问题。

我可以播放一次视频,没有任何问题。

当用户按下done时,我关闭mediaplayer,并将用户移回上一个屏幕。(我正在使用一个基于导航的应用程序)。

但是,当我尝试通过按播放按钮再次启动视频时,媒体播放器控制器不再正常工作。

我看到的只是一个黑屏。没有视频,没有声音。

在得到MPMoviePlayerPlaybackDidFinishNotification或MPMoviePlayerDidExitFullscreenNotification之后,我已经发布了之前的媒体播放器控制器。

任何建议都将不胜感激。

更多信息-以下是我的代码片段:

代码语言:javascript
复制
- (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];
}  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-15 16:48:02

代码语言:javascript
复制
-(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];

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6632492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档