このコードについて教えてください。ビデオを再生しようとしていますが、Exc_bad_Access コード = 1 のエラーが発生し、コード = 2 の場合もあります。
-(IBAction)BtnPressed:(id)sender{
self.videoview.hidden = false;
NSString *btnTag = [NSString stringWithFormat:@"%d",[sender tag]];
NSString *videofilename = [NSString stringWithFormat:@"%@%@_%@", selectedGender, btnTag, selectedVowel];
//Playing video
NSString *filepath = [[NSBundle mainBundle] pathForResource:videofilename ofType:@"mp4"];
NSLog(@"file name is %@",filepath);
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
//NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:btnTag ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playercontroller];
//[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//playercontroller.moviePlayer.scalingMode = MPMovieScalingModeNone;
playercontroller.moviePlayer.controlStyle = MPMovieControlStyleNone;
[playercontroller.view setFrame:CGRectMake(30, 50, 150, 200)];
[self.videoview addSubview:playercontroller.view];
[playercontroller.moviePlayer prepareToPlay];
[playercontroller.moviePlayer play];
//playercontroller = nil;
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
アドバイスお待ちしております