I create one application that show file in document folder.
I have one file .mov format that I want show it from document folder but when run app and click play button don't show this movie and I see this image
:
this is my code : (please guide me and tell me my mistake)
- (IBAction)Play:(id)sender
{
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *file = [documentPath stringByAppendingPathComponent:@"xcode4-outlet.mov"];
NSURL *url = [NSURL fileURLWithPath:file];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:_moviePlayer.view];
_moviePlayer.fullscreen = YES;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.allowsAirPlay = YES;
[_moviePlayer play];
}
also compiler get me this massage :
movie player[9489:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
movie player[9489:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
movie player[9489:c07] [MPAVController] Autoplay: Enabling autoplay
movie player[9489:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
movie player[9489:c07] [MPAVController] Autoplay: Enabling autoplay
You need to check whether a file is there or not before adding movie player also you can add default
-(IBAction)Play:(id)sender
{
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *file = [documentPath stringByAppendingPathComponent:@"xcode4-outlet.mov"];
NSURL *url = [NSURL fileURLWithPath:file];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:file];
if(fileExists)
{
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification
object:_moviePlayer];
_moviePlayer.shouldAutoplay=NO;
[_moviePlayer prepareToPlay];
}
}
Add your movie after movie is completely loaded
-(void)moviePreloadDidFinish:(NSNotification*)notification
{
_moviePlayer.controlStyle=MPMovieControlStyleDefault;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer play];
[_moviePlayer setFullscreen:YES animated:YES];
}