Newbee
Newbee

Reputation: 3301

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?

Upvotes: 0

Views: 1021

Answers (1)

Vivek Sehrawat
Vivek Sehrawat

Reputation: 6570

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

Upvotes: 4

Related Questions