I am using the mediaplayer framework included in iOS 6 to try and play a movie from within an app. I import and then:
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
The view goes to blank screen and infinite loading when this function is called. I have tried many other versions of this implementation and the results vary and all fail. The log in the is particular case is:
2012-11-05 21:19:27.900 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.902 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.977 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.978 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.984 [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-11-05 21:19:28.156 [MPAVController] Autoplay: Enabling autoplay
Got ideas on the cause? This is my first venture into playing video and it has turned out to be a nightmare at this point.
In .h file add the following
try this
The problem of your code is that the variable "moviePlayerController" is just local scope, so right after you invoke
[moviePlayerController play];
and exit the function the local variable was release (because there is an asyn operation here with play method to play from queue). It doesn't keep content refer to URL anymore. So you see a black screen and an infinitive "Loading..."You need to declare an instance variable of class and copy the content from local variable to class's property, like the example code from @iAppDeveloper above. It should work!