I am trying to play a video by MPMoviePlayerController in iOS 6.0 by two methods.
Here is the snippet for it.
-(void) playMovie
{
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setContentURL:self.movieURL];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayer.view setFrame:CGRectMake ( 0, 0, 320, 476)];
[self.view addSubview:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
[self.moviePlayer play];
}
I tried taking the property moviePlayer
as both strong and retain but no use.
My problem is very much similar to this Question, that the video stops within one second. However if you are playing a video which is over internet it works fine.
Here is the Git Source Code for What I have tried
I found the issue with this.
I am using this for iPad hence I use a UIPopoverController
to select video from library and after selection is done I dismiss the popover in didFinishPickingMediaWithInfo
and call the function playMovie
(written above)
The problem here was if dismiss popover the moviePlayer is also removed.
Though I didn't get why this happened, I wrote a work around for this by saving the URL path globally and adding an additional play button to start the movie after dismissing the popover. The complete code is here