0

iOS アプリを開発しており、ユーザーがボタンを押したときにビデオを再生したいと考えています。私はこれを開発しました。ユーザーがボタンを押すとビデオが再生されますが、ビデオが終了するとビデオのビューが残り、ビデオの最後のフレームでフリーズします。

Google で検索したところ、次の質問が見つかりました。

iOS 6、Xcode 4.5 ビデオの再生が終了しても終了しない

そこに書かれたコードを使用しましたが、修正していません。これは私のコードです:

-(IBAction)reproducirVideo:(id)sender
{
NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"instrucciones"     ofType:@"mp4"]];
_moviePlayer =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{
[_moviePlayer.view removeFromSuperview];
_moviePlayer = nil;
}


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
[_moviePlayer stop];
[_moviePlayer.view removeFromSuperview];
_moviePlayer = nil;
}
4

1 に答える 1

1

ご迷惑をおかけして申し訳ありませんが、この質問を読んで修正しました:

MPMoviePlayerController は、再生終了後にムービーを自動的に閉じません (ios 6)

これは正しいコードです:

- (IBAction)reproducirVideo:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"instrucciones" ofType:@"mp4"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
 initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:_moviePlayer];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

MPMoviePlayerController *player = [notification object];

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:player];

if ([player
     respondsToSelector:@selector(setFullscreen:animated:)])
{
    [player setFullscreen:NO animated:YES];
    [player.view removeFromSuperview];
}
}

ありがとうジェイセン!!! あなたは私の命を救いました

よろしくお願いします

于 2013-07-05T09:29:56.747 に答える