0

我需要MPMoviePlayerController在播放时以编程方式退出,而不是按完成按钮。是否可以。有没有办法模拟完成按钮点击?

4

1 回答 1

4

我有一个窍门给你。你可以在uiview上拿mpmovieplayer,然后在停止播放器后删除uiview

在 ViewController.h

      MPMoviePlayerController *moviePlayerController;
      UIView *view1;
    -(IBAction)cancelPlay:(id)sender;

在 ViewController.m 中

  - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"try" ofType:@"mp4"];
        NSURL *fileURL = [NSURL fileURLWithPath:filepath];
        view1=[[UIView alloc]initWithFrame:CGRectMake(0, 10, 320, 300)];
        view1.backgroundColor=[UIColor blueColor];
        [self.view addSubview:view1];
        moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [moviePlayerController.view setFrame:CGRectMake(0, 10, 320,300)];
        [view1 addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;
        moviePlayerController.controlStyle=MPMovieControlStyleEmbedded;
        [moviePlayerController play];
    }
    -(IBAction)cancelPlay:(id)sender{
        [moviePlayerController stop];
        [view1 removeFromSuperview];
    }
于 2013-06-17T10:46:48.903 回答