0

你能帮我这个代码吗,我正在尝试播放视频,但我遇到错误 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];
    }    
}

等待您的建议

4

1 回答 1

0

看起来您的 MPMoviePlayerViewController 没有保留,因此它可能已被删除。

于 2013-07-09T17:01:48.940 回答