2011-07-09 8 views
0

Iphoneのmediaplayercontrollerに問題があります。Iphone mpmediaplayerController、ユーザーが完了した後にビデオを再起動できない

私は問題なくビデオを一度再生することができます。

ユーザーが完了を押すと、メディアプレーヤーを閉じて、ユーザーを前の画面に戻します。 (私はナビゲーションベースのアプリケーションを使用しています)。

ただし、再生ボタンを押してビデオを再開しようとすると、mediaplayerコントローラは正しく動作しなくなります。

私は黒い画面が表示されます。ビデオも音もない。

私は既にMPMoviePlayerPlaybackDidFinishNotificationまたはMPMoviePlayerDidExitFullscreenNotificationを取得した後、以前のmediaplayperコントローラをリリースしました。

アドバイスをいただければ幸いです。

詳細-------ここ は、私のコードの抜粋です、あなたがプレイヤーを解放言及

- (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]; 
} 
+0

ので、念のために、あなたは右の新しいインスタンスを作成しています?また、MPMoviePlayerPlaybackDidFinish通知が実際に呼び出されていることを確認します。 – Keller

+0

完了ボタンを押すとMPMoviePlayerDidExitFullscreenNotificationが呼び出されます。 ご覧のとおり、新しいビデオを再生しようとするたびに、mediaplayerの新しいインスタンスを作成しました。 – russell

答えて

0
-(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]; 

} 
関連する問題