2012-07-09 48 views
1

我將視頻從照片庫存儲在我的文檔目錄中。現在我想顯示存儲在我的文檔目錄中的所有視頻..但我不知道它有可能如何? 其實我想顯示所有的視頻像它的照片庫(四個視頻中的單行)..當我點擊任何視頻...視頻開始播放...顯示存儲在文檔目錄中的所有視頻

任何人都可以幫助我這是爲了顯示從文件目錄的ViewController .... 感謝名單的所有視頻的最佳方式......

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    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 imageNameTextField]text]]; 
    fullPath = [fullPath stringByAppendingFormat:@".MOV"]; 
    [ movieData writeToFile:fullPath atomically:YES]; 

} 
+0

您的文檔目錄是否只包含MOV視頻或其他文件? – 2012-07-09 07:53:43

+0

只有mov文件........ – Rox 2012-07-09 07:54:55

+0

那麼在這種情況下,您可以獲取文檔目錄的所有文件。你知道怎麼做嗎?或者我應該告訴你它的代碼? – 2012-07-09 08:01:48

回答

2

我建議你使用一個開源網格視圖控件。你可以在GitHub中找到它們。例如,BDDynamicGridViewController很有趣。但它不是唯一的選擇。還有AQGridView

此外,還有一個流行的開源庫,名爲Three20,它有升級,名爲Nimbus。這個庫有一個顯示照片網格的自定義控件。您可以使用相同的方式顯示視頻縮略圖網格。例如,請嘗試this

在您將設法使用或創建網格視圖控制後,您需要縮略圖生成器來處理視頻。爲此目的使用this topic

+0

thanx wzbozon,它對我非常有幫助.... – Rox 2012-07-09 09:01:22

0

要訪問存儲在設備照片庫中的視頻,您需要使用資源庫。下面的代碼演示瞭如何獲得訪問第一視頻在照片庫:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 


// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos. 

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 


// Within the group enumeration block, filter to enumerate just videos. 

[group setAssetsFilter:[ALAssetsFilter allVideos]]; 


// For this example, we're only interested in the first item. 

[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0 

     usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) { 

     // The end of the enumeration is signaled by asset == nil. 

     if (alAsset) { 

      ALAssetRepresentation *representation = [alAsset defaultRepresentation]; 

      NSURL *url = [representation url]; 

      AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil]; 

      // Now you have the AV asset for the video. 

     } 

     }]; 

    } 

    failureBlock: ^(NSError *error) { 

    // Typically you should handle an error more gracefully than this. 

    NSLog(@"No groups"); 

    }]; 


[library release]; 

這個例子是AVFoundation編程指南中,對Apple developer website

+0

Thanx werner ...但我想要獲取視頻文檔目錄 – Rox 2012-07-09 07:48:53

+0

好的,這意味着你需要複製或移動它們,對吧?這就是爲什麼我更願意直接從照片庫中顯示它們的原因。你將如何展示他們?您可能需要生成縮略圖才能顯示它們。 AQGridView是一個很好的庫,可以將它們顯示在您自己的ViewController中。 – werner 2012-07-09 07:51:48

+1

是的,我想從照片庫中移動視頻,當我錄製它也存儲在我的文檔目錄中的任何視頻...我不知道如何顯示所有電影..所以我問這個問題 – Rox 2012-07-09 07:57:36

0

更多的細節我也犯了同樣項目我的客戶之一。我可以告訴你這個想法,但不能告訴你代碼。這個想法是在拍攝或保存視頻時將每個視頻的起始幀保存爲PNG圖像作爲視頻的圖標。通過這種方式,您將獲得每個視頻的圖標。將所有圖像保存在不同的文件夾中,以便每個圖像都可以與其視頻鏈接。現在,通過下面的代碼檢索文件夾中的所有視頻

NSFileManager *filemgr; 
filemgr = [NSFileManager defaultManager]; 
filelist = [filemgr contentsOfDirectoryAtPath:path error:nil]; 

*文件列表是NSArray的

以同樣的方式獲取的視頻圖標。

製作按鈕的網格視圖。將按鈕的圖像設置爲視頻的圖標。顯示視頻名稱。當點擊視頻時,打開一個新的視圖控制器,讓視頻播放器在那裏播放視頻。

+0

可以üPLZ解釋如何保存每個視頻的起始幀,並將其保存爲視頻圖標.... – Rox 2012-07-09 08:22:46

+0

Thanx爲這個想法。 ...... – Rox 2012-07-09 09:00:17

+0

http://www.codza.com/extracting-frames-from-movies-on-iphone此鏈接將幫助你從視頻中提取幀 – 2012-07-09 09:11:55

相關問題