0

I am playing video in iphone application i want that when done button is clicked player should move back to original view from where it played.

I am using following code

  viewDidLoad(){
     [self play];
  }

  -(void)play{
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
    NSURL    *url    = [NSURL fileURLWithPath:urlStr];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0, 0, 1024, 768);  
    [moviePlayer play];
  }
hol
  • 8,255
  • 5
  • 33
  • 59
user1602302
  • 5
  • 1
  • 4

1 Answers1

3

You should call this notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

Try this(I did this for IPad):

self.player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

self.player.view.frame = CGRectMake(0, 0, 1024, 748);
[self.view addSubview:self.player.view];
[self.player setFullscreen:YES animated:YES];
[self.player play];

and when done button clicked:

-(void)doneButtonClicked
{
    [self.player stop];
    [self.player.view removeFromSuperview];
    [self.navigationController popViewControllerAnimated:YES];//no need this if you are opening the player in same screen;
}
Community
  • 1
  • 1
alishaik786
  • 3,696
  • 2
  • 17
  • 25
  • it crasehd application when done button is clicked unrecognised selectro sent – user1602302 Aug 16 '12 at 06:19
  • i am playing this in the subView – user1602302 Aug 16 '12 at 06:33
  • I think you are opening the moviePlayer in the same screen. I am opening in the different screen. If you opened it in the same screen, remove this statement from (void)doneButtonClicked method: "[self.navigationController popViewControllerAnimated:YES]; " Check the code I edited now – alishaik786 Aug 16 '12 at 06:34
  • That show your internal issue; check this link: http://stackoverflow.com/questions/8151301/nsinvalidargumentexception-unrecognized-selector-sent-to-instance-using-mpmov – alishaik786 Aug 16 '12 at 06:54
  • ok but can you tell me that when i play same this file uploaded to server and from url then it gives the following error An AVPlayerItem cannot be associated with more than one instance of AVPlayer' – user1602302 Aug 16 '12 at 07:03
  • can you help in this queery which i have stated – user1602302 Aug 16 '12 at 07:35