user2296278
user2296278

Reputation: 528

iOS ,NSDocumentDirectory get the nsurl or path file

i have this code for saving the mp3 files

NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDirectory = [documentPath objectAtIndex:0];

    NSString *fileName = [[NSString alloc] initWithFormat:@"%@%@.mp3", dateString ,timeString ];


    NSURL* fileURL = [NSURL URLWithString:myString];
    NSError* error = nil;
    NSData* data = [NSData dataWithContentsOfURL:fileURL options:0 error:&error];

     NSString *savePath = [docDirectory stringByAppendingPathComponent:fileName];

    [data writeToFile:savePath atomically:YES];

now i want read this file by MPMoviePlayerController

how can get the path or nsurl file

--- somthing code same this

 NSURL * urlv = [[NSURL alloc] initWithString:myString];
     avPlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlv];
    [avPlayer prepareToPlay];
    [avPlayer play];

please help for searching the mystrig or nsurl source

Upvotes: 3

Views: 6649

Answers (1)

Tommy Devoy
Tommy Devoy

Reputation: 13549

NSString *filename = @"whatever you've saved your filename as";
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [pathArray objectAtIndex:0];
NSString *yourSoundPath = [documentsDirectory stringByAppendingPathComponent:filename];

if ([[NSFileManager defaultManager] fileExistsAtPath:soundPath])
{
    NSURL *soundURL = [NSURL fileURLWithPath:soundPath isDirectory:NO];
}

//Then just init your player with the contents of that URL

Upvotes: 8

Related Questions