I have this function to write NSData to document dictionary -
- (void)writeData
{
NSString *str = @"http://labs.widespace.com/resources/banner/ikea/verkligheten/video.m4v";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:str];
NSLog(@"%@",path);
NSLog(@"About to Write Data");
NSData* data0 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]];
[data0 writeToFile:path atomically:YES];
NSLog(@"Writting Data Completed");
}
Later i read this data and try to play the video using MPMoviePlayerController, but unfortunately this does not play-
- (void)readData
{
NSString *str = @"http://labs.widespace.com/resources/banner/ikea/verkligheten/video.m4v";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:str];
NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
NSLog(@"url:%@",url);
NSError *error = nil;
BOOL isReacahble = [url checkResourceIsReachableAndReturnError:&error];
NSLog(@"isReachable :%i,%@",isReacahble,error);
BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:path];
if(fileExist)
{
NSLog(@"File Exist in path");
}
else
{
NSLog(@"NO File Exist");
}
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer prepareToPlay];
NSLog(@"movie player:%@",moviePlayer);
[moviePlayer setControlStyle: MPMovieControlStyleFullscreen];
[moviePlayer.view setFrame:CGRectMake(0, 0,320, 480)];
[self.view addSubview:moviePlayer.view];
moviePlayer.shouldAutoplay = YES;
[moviePlayer play];
}
When i try to play this it shows following error-
2013-01-17 11:21:07.067 VideoCheck[338:907] [MPAVController] Autoplay: Disabling autoplay for pause
2013-01-17 11:21:07.068 VideoCheck[338:907] [MPAVController] Autoplay: Disabling autoplay
2013-01-17 11:21:07.090 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-17 11:21:07.091 VideoCheck[338:907] movie player:<MPMoviePlayerController: 0x21078250>
2013-01-17 11:21:07.093 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-17 11:21:07.102 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-17 11:21:07.113 VideoCheck[338:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-17 11:21:07.114 VideoCheck[338:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2013-01-17 11:21:07.115 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
2013-01-17 11:21:07.121 VideoCheck[338:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-17 11:21:07.149 VideoCheck[338:907] [MPAVController] Autoplay: Enabling autoplay
Can someone please run the code and provide some information about what's happening here??Please someone help me. I am using iOS 6.
In your wrieData
method, instead of giving URL
name as file, give only the name of the video
. Like
NSString *path = [documentsDirectory stringByAppendingPathComponent:[str lastPathComponent]];
and do the same in readData
method too.