Search code examples
iphoneiosobjective-ccocoa-touchmpmovieplayercontroller

How to quit MPMoviePlayerController programmatically?


I need to quit the MPMoviePlayerController programmatically while playing, instead of pressing done button. Is it possible. Is there any way to simulate Done button click?


Solution

  • i have one trick for you. you can take the mpmovieplayer on uiview and then remove the uiview after stoping the player

    In ViewController.h

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

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