簡體   English   中英

如何獲取NSdocument目錄保存的視頻

[英]How to get NSdocument directory saved video

目前,我正在開發一個應用程序,其中我已將錄制的視頻保存到文檔目錄和我的

代碼在這里:

     NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;

     NSData * movieData = [NSData dataWithContentsOfURL:movieURL];

     NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

     NSString *documentsDirectory = [documentPaths objectAtIndex:0];

     NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self video]text]];

     fullPath = [fullPath stringByAppendingFormat:@".MOV"];

      [movieData writeToFile:fullPath atomically:YES];

現在如何檢查視頻是否保存在文檔目錄中?

您可以使用此代碼獲取所有保存的視頻:-

-(IBAction)getallVideo
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *library = [path objectAtIndex:0];

    NSArray *fileArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:library error:nil];

    videolist  = [[NSMutableArray alloc]init];

        for(int i = 0;i<fileArray.count;i++){
    NSLog(@"table%d",fileArray.count);
    id myArrayElement = [fileArray  objectAtIndex:i];
    if([myArrayElement rangeOfString:@".mp4" ].location !=NSNotFound)
    {
        [videolist addObject:myArrayElement];

    }
    else if([myArrayElement rangeOfString:@".mov"].location !=NSNotFound)
    {

    [videolist addObject:myArrayElement];
    }
 NSLog(@"Mu %@",videolist);

}
BOOL _isSaved = [movieData writeToFile:fullPath atomically:YES];

if(_isSaved == YES)}

   NSLog(@"Saved Succesfully")
}
else{

     NSLog(@"Error occured");
}

或者

 NSError* error;
[movieData writeToFile:storePath options:NSDataWritingAtomic error:&error];

if(error == nil){

  NSLog(@"Saved Succesfully")

}
 else{

         NSLog(@"write error %@", error);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM