Search code examples
iphoneiosuiwebviewvideo-streamingresourcebundle

How can i store streaming video in resource folder in iOS?


If i go to the point then my problem is, i want to make a web view where it will load a video and when stream starts then i want to download/store that video data in the resource folder of the application.How can i do that?

Please somebody help me by any kinds of help.

BR

Emon


Solution

  • In the run time you can't save a video to resource folder but you can save files in to NSDocuments and retrive them using NSFileManagers.Go through this link http://www.techotopia.com/index.php/Working_with_Files_on_the_iPhone

    Try with this Code to save a file

     NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0];                    
     NSString *filePath = [NSString stringWithFormat:@"%@/filename.MP4",documentsDirectory];
     NSData*   videoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your Url"]];
     [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
     [filemanager createFileAtPath:filePath contents:videoData attributes:nil];
    

    To retrive:

     NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0];                    
     NSString *filePath = [NSString stringWithFormat:@"%@/filename.MP4",documentsDirectory];
        BOOL exists = [fm fileExistsAtPath:newDirectory isDirectory:&isDir];
        if (exists) {
         //Play Video with contents of file path. 
    
          }