How to get thumbnails of a video saved in document directory - iphone

I saved the captured video in document directory as shown below and now I want to display the thumbnails and play the same video.How to do this ?
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:NO];
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *movieName = [NSString stringWithFormat:#"%#.mov",[CoreDataFunctions getNameForVideoForDate:[CalendarFunctions getCurrentDateString]]];
NSString *moviePath = [documentsDir stringByAppendingPathComponent:movieName];
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL];
NSData * movieData = [NSData dataWithContentsOfURL:movieURL];
NSLog(#"%#",moviePath);
if([movieData writeToFile:moviePath atomically:NO])
{
if(![CoreDataFunctions saveVideoInfoInDatabaseForDate:[CalendarFunctions getCurrentDateString]])
{
NSLog(#"Video was saved in doucment directory but could not be saved in core data");
}
}
else
{
NSLog(#"Video could not be saved to the document directry");
}
}
}

Get videos from doc dir like this
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError * error;
NSArray *directoryContents = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:documentsDirectory error:&error];
//Take all images in NSMutableArray
NSMutableArray *arrVideoImages = [[NSMutableArray alloc]init];
for(NSString *strFile in directoryContents)
{
NSString *strVideoPath = [NSString stringWithFormat:#"%#/%#",documentsDirectory,strFile];
UIImage *img = [self getThumbNail:strVideoPath];
[arrVideoImages addObject:img];
}
Also add this method:
-(UIImage *)getThumbNail:(NSString)stringPath
{
NSURL *videoURL = [NSURL fileURLWithPath:stringPath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
[player release];
return thumbnail;
}

Related

NOt able to convert from MPMediaItem(mp3 song) to NSData

I have tried following code :
These is my delegate method of MPMediPickerController :
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
// Dismiss the media item picker.
[self dismissModalViewControllerAnimated: YES];
NSLog(#"%# %d",mediaItemCollection,mediaItemCollection.count);
NSArray *newMediaItem= [mediaItemCollection items];
MPMediaItem *item=[[newMediaItem objectAtIndex:0] retain];
[self uploadMusicFile:item];
}
This is my custom method MPMediaItem to NSData:
- (void) uploadMusicFile:(MPMediaItem *)song
{
NSURL *url = [song valueForProperty: MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset
presetName: AVAssetExportPresetPassthrough];
exporter.outputFileType = #"public.mpeg-4";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *exportFile = [documentsDirectory stringByAppendingPathComponent:
#"exported.mp4"];
NSURL *exportURL = [[NSURL fileURLWithPath:exportFile] retain];
exporter.outputURL = exportURL;
[exporter exportAsynchronouslyWithCompletionHandler:
^{
NSData *data = [NSData dataWithContentsOfFile: [documentsDirectory
stringByAppendingPathComponent: #"exported.mp4"]];
NSLog(#"%#",data);
}];
}
I am getting "null" in NSlog.
I have also check this post :
how to convert nsdata to MPMediaitem song iOS Sdk
but not getting solution.
I am using xcode 4.6 and ios 6.1.
Can any one tell me what is wrong here?

Saving image persistently in within App - iOS

Trying to select image using photo picker and save that image internally in apps folder.
- (void) imagePickerController: (UIImagePickerController *) pickerdidFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToUse;
// Handle a still image picked from a photo album
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToUse = editedImage;
} else {
imageToUse = originalImage;
}
// Do something with imageToUse
//save it
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imageName = [documentsDirectory stringByAppendingString:[NSString stringWithFormat:#"%d", myUniqueID]];
NSString *imagePath = [imageName stringByAppendingPathComponent:#".png"];
NSData *webData = UIImagePNGRepresentation(editedImage);
NSError* error = nil;
bool success = [webData writeToFile:imagePath options:NULL error:&error];
if (success) {
// successfull save
imageCount++;
[[NSUserDefaults standardUserDefaults] setInteger:imageCount forKey:#"imageCount"];
NSLog(#"#Success save to: %#", imagePath);
}
else if (error) {
NSLog(#"Error:%#", error.localizedDescription);
}
}
...
}
What I can't figure out is that writeToFile::: returns false but no value is returned in error so I can't figure out whats going wrong. Any help would be greatly appreciated thanks
You're missing a "/". The line:
NSString *imageName = [documentsDirectory stringByAppendingString:[NSString stringWithFormat:#"%d", myUniqueID]];
should be:
NSString *imageName = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%d", myUniqueID]];
And the line that says:
NSString *imagePath = [imageName stringByAppendingPathComponent:#".png"];
should be:
NSString *imagePath = [imageName stringByAppendingPathExtension:#"png"];
Update:
And, shouldn't:
NSData *webData = UIImagePNGRepresentation(editedImage);
be the following?
NSData *webData = UIImagePNGRepresentation(imageToUse);

How save images in home directory?

I am making an application in which i have use Json parsing. With the help of json parsing i get photo url which is saved in string. To show images in my cell i use this code
NSString *strURL=[NSString stringWithFormat:#"%#", [list_photo objectAtIndex:indexPath.row]];
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: strURL]];
CGRect myImage =CGRectMake(13,5,50,50);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImage];
[imageView setImage:[UIImage imageWithData: imageData]];
[cell addSubview:imageView];
Now prblem is that when i go back or forword then i have wait for few second to come back on same view. Now i want that i when application is used first tme then i wait for that screen otherwise get images from home directory. How i save these image in my home directory? How access from home directory?
You can save an image in the default documents directory as follows using the imageData;
// Accessing the documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"myImage.png"];
//Writing the image file
[imageData writeToFile:savedImagePath atomically:NO];
You can use this to write a file to your Documents Folder
+(BOOL) downloadFileFromURL:(NSString *) url withLocalName:(NSString*) localName
{
//Get the local file and it's size.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:localName];
NSError *error;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:finalPath error:&error];
NSAssert (error == nil, ([NSString stringWithFormat:#"Error: %#", error]));
if (error) return NO;
int localFileSize = [[fileAttributes objectForKey:NSFileSize] intValue];
//Prepare a request for the desired resource.
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"HEAD"];
//Send the request for just the HTTP header.
NSURLResponse *response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSAssert (error == nil, ([NSString stringWithFormat:#"Error: %#", error]));
if (error) return NO;
//Check the response code
int status = 404;
if ([response respondsToSelector:#selector(statusCode)])
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
status = [httpResponse statusCode];
}
if (status != 200)
{
//file not found
return NO;
}
else
{
//file found
}
//Get the expected file size of the downloaded file
int remoteFileSize = [response expectedContentLength];
//If the file isn't already downloaded, download it.
if (localFileSize != remoteFileSize || (localFileSize == 0))
{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
[[NSFileManager defaultManager] createFileAtPath:finalPath contents:data attributes:nil];
return YES;
}
//here we may wish to check the dates or the file contents to ensure they are the same file.
//The file is already downloaded
return YES;
}
and this to read:
+(UIImage*) fileAtLocation:(NSString*) docLocation
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:docLocation];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
[[NSFileManager defaultManager] createFileAtPath:finalPath contents:data attributes:nil];
NSData *databuffer = [[NSFileManager defaultManager] contentsAtPath:finalPath];
UIImage *image = [UIImage imageWithData:databuffer];
return image;
}

Save the The Stream From URL

In my project I am connecting a url and I am watching a video with MPMoviePlayerViewController. But that is not enough to me. I also want to save the file to my Iphone. I have to buttons. one is watch the video, the other is save the video. When I push the button watch I am watchng it. But unable to save it. by this I want to be able to watch the video later. So in another view I want to see saved videos etc. Is there any one can help me or can show the way ? I have tried following code phrase but When the code started, It works for a while (probably it is the download time), but when it is time to save I get Bad EXC_BAD_ACCESS error .Thanks every one.
Here is my code .
CFStringRef *docsDirectory = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: #"recordedFile.mp4"];
NSString *temPath=NSTemporaryDirectory();
NSString *tempfile=[temPath stringByAppendingPathComponent:#"recode.mp4"];
NSLog(#" DOSYA ADI MADI %#",docsDirectory);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
[fileManager removeItemAtPath:docsDirectory error:&error];
NSURL *url = [NSURL URLWithString:#"http://video.teknomart.com.tr/3-13-2.mp4"];
NSMutableURLRequest *liveRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[liveRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[liveRequest setValue:#"headervalue" forHTTPHeaderField:#"headerfield"];
NSURLResponse *response;
NSData *myData = [NSURLConnection sendSynchronousRequest:liveRequest returningResponse:&response error:&error];
NSData *myData2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://video.teknomart.com.tr/3-13-2.mp4"]];
NSString *myString=[[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
NSLog(#"gelen sey %#",myString);
[myString writeToFile:tempfile writeToFile:tempfile automatically:YES encoding:NSASCIIStringEncoding error:nil];
[myString release];
return true;
-(void)viewDidLoad {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSArray *myWords = [songNameString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSLog(#"%#",[myWords lastObject]);
NSURL *url = [NSURL fileURLWithPath:appFile];
NSLog(#"%#",url);
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden=YES;
currentTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(showCurrentTime) userInfo:nil repeats:YES];
alarmTimeLabel.text =alarmTimeString;
alarmSongLabel.text = [myWords lastObject] ;
[self performSelector:#selector(loadVideoInBackground)];
//[NSThread detachNewThreadSelector:#selector(loadVideoInBackground) toTarget:self withObject:nil];
}
-(void)loadVideoInBackground
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSString *appFile;
NSArray *myWords = [songNameString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSFileManager *fileMgr=[NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:appFile]) {
alarmCanPlay = FALSE;
NSURL *imageURL = [[[NSURL alloc] initWithString:songNameString]autorelease];
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:imageURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
imageConnection = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
if(imageConnection)
{
videoData = [[NSMutableData data] retain];
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// this method is called when the server has determined that it
// has enough information to create the NSURLResponse
// it can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.
// receivedData is declared as a method instance elsewhere
[videoData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
//NSLog(#"%d",[data size]);
[videoData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// release the data object
[videoData release];
// inform the user
NSLog(#"Connection failed! Error - %# %#", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
//workInProgress = NO;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSString *appFile;
NSArray *myWords = [songNameString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
[videoData writeToFile:appFile atomically:YES];
alarmCanPlay = TRUE;
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSArray *myWords = [songNameString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSLog(#"%#",[myWords lastObject]);
NSURL *url = [NSURL fileURLWithPath:appFile];
NSLog(#"%#",appFile);
self.videoMPPlayer =[[MPMoviePlayerController alloc] init];
videoMPPlayer.view.frame = CGRectMake(0, 0, 768, 1024);
videoMPPlayer.scalingMode = MPMovieScalingModeAspectFill;
videoMPPlayer.controlStyle = MPMovieControlStyleNone;
videoMPPlayer.shouldAutoplay = NO;
[videoMPPlayer pause];
This is What I have in my code. It looks like it is downloading movie . But I cant find the file. also I run it in the similator . nofile that named with my moviename was in tmp dir. What is wrong or missing ?
-(void)viewDidLoad
{
[super viewDidLoad];
NSString *documentsDirectory = NSTemporaryDirectory();
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
downloaded=FALSE;
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:#"mymoview.mp4"];
NSURL *url = [NSURL fileURLWithPath:appFile];
NSLog(#"%#",url);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden=NO;
timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(showVideo) userInfo:nil repeats:YES];
[self performSelector:#selector(loadVideoInBackground)];
[NSThread detachNewThreadSelector:#selector(loadVideoInBackground) toTarget:self withObject:nil];
}
-(void)showVideo{
NSString *homeDir = NSHomeDirectory();
NSString *tempDir = NSTemporaryDirectory();
// Format output
NSString *s =
[NSString stringWithFormat:#"homeDir:\n"
#"%#\n"
#"tempDir:\n"
#"%#\n",
homeDir,
tempDir];
NSLog(#" %# ",s);
if (downloaded) {
NSLog(#"burdayim");
NSString *documentsDirectory = NSTemporaryDirectory();
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSString *appFile;
appFile = [documentsDirectory stringByAppendingPathComponent:#"mymoview.mp4" ];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"myvoview" ofType:#"mp4" inDirectory:#"/tmp"];
NSLog(#" %# lafta oynatilan dosya ",filePath);
NSFileManager *fileMgr=[NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:filePath]) {
NSLog(#"dosya yok");
}
else
{
NSLog(#"dosyayi da buldum");
NSURL *movieURL = [NSURL fileURLWithPath:appFile];
NSLog(#" %# lafta oynatilan dosya ",appFile);
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[player setFullscreen:YES];
[self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
player.fullscreen=YES;
//self.view.autoresizesSubviews=YES;
//[self presentModalViewController:player animated:YES];
self.view=player.view;
[player play];
}
}
}
-(void)loadVideoInBackground{
NSString *documentsDirectory = NSTemporaryDirectory();
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSString *appFile;
appFile = [documentsDirectory stringByAppendingPathComponent:#"mymoview.mp4" ];
NSFileManager *fileMgr=[NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:appFile]) {
NSURL *videoURL = [[[NSURL alloc] initWithString:#"http://video.teknomart.com.tr/3-13-2.mp4"] autorelease];
NSURLRequest *videoRequest = [NSURLRequest requestWithURL:videoURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
videoconnection = [[NSURLConnection alloc] initWithRequest:videoRequest delegate:self];
if(videoconnection)
{
videoData = [[NSMutableData data] retain];
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//[videoData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
NSLog(#" bisiler yukleniyor ");
[videoData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[videoData release];
NSLog(#"Connection failed! Error - %# %#", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}else
{
NSString *appFile;
appFile = [documentsDirectory stringByAppendingPathComponent:#"mymoview.mp4"];
[videoData writeToFile:appFile atomically:YES];
downloaded = TRUE;
NSLog(#"Yuklandi");
}
}
}

how to stream a video in iphone

does initWithContentURL: in MPMoviePlayerController download the video file at first and then start playing or will it stream file like in youtube?
I want to play an video located in server through streaming in order not to waste of time.
How to perform streaming in iphone?
Can anyone please suggest me if u know.
Thanks in advance.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSString *appFile;
NSArray *myWords = [[NSString stringWithFormat:#"%#",[[videolistArray objectAtIndex:[number intValue]] valueForKey:#"video"]] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSFileManager *fileMgr=[NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:appFile]) {
NSData *imageData;
NSURL *imageURL = [[[NSURL alloc] initWithString:[[videolistArray objectAtIndex:[number intValue]] valueForKey:#"video"] ] autorelease];
if (imageURL) {
imageData = [NSData dataWithContentsOfURL:imageURL];
}
[imageData writeToFile:appFile atomically:YES];
}
[pool release];
if (spinner) {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
spinner = nil;
}
---------------------------Above methode is for save video in file system of iphone
-------------------- Below method to play that movie continuos
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(#"Documents directory not found!");
}
NSArray *myWords = [videoString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"/"]];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSLog(#"%#",[myWords lastObject]);
NSURL *url = [NSURL fileURLWithPath:appFile];
self.videoMPPlayer =[[MPMoviePlayerController alloc] initWithContentURL:url];
self.videoMPPlayer.view.frame = CGRectMake(0, 0, 320, 480);
self.videoMPPlayer.scalingMode = MPMovieScalingModeAspectFill;
self.videoMPPlayer.controlStyle = MPMovieControlStyleNone;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieLoadStateChanges:) name:MPMoviePlayerLoadStateDidChangeNotification object:videoMPPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoMPPlayer];
// Movie playback is asynchronous, so this method returns immediately.
[self.videoMPPlayer play];