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;
}