2013-08-25 3 views
1

감사합니다. 내 응용 프로그램의 문서 디렉토리에있는 파일의 이름을 읽고 나열하는 코드가 있습니다. 이 잘 작동하고 난 그래서 난이 코드 발견 내가 얻을 비디오의 각에서 thumnails을 추가 할 알고 : 그것은 다른 추가 그래서 잘 모르겠어요 그러나Objective-C : thumbnail을 TableView에 추가하는 방법 비디오에서?

NSURL *videoURL = [NSURL fileURLWithPath:@""]; 
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 

UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 
cell.imageView.image = thumbnail; 
[player stop]; 

내 파일의 경로를 가리을 내 tableview가 표시하는 모든 개별 비디오의 썸네일. 사전에

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; 
    } 


    NSLog(@"urlstring %@",[filePathsArray objectAtIndex:indexPath.row]); 


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil]; 


    cell.textLabel.text = [filePathsArray[indexPath.row] lastPathComponent]; 
    filePathsArray = [[NSArray alloc] initWithArray: [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil]mutableCopy]]; 

    NSURL *videoURL = [NSURL fileURLWithPath:@""]; 
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 

    UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 
    cell.imageView.image = thumbnail; 
    [player stop]; 
    return cell; 


} 

감사 :

는 여기에 내가 비디오 파일을 받고 표에 표시하고 있습니다 내 전체 코드입니다.

답변

0

cellForRowAtIndexPath에서이 작업을 수행하면 안됩니다. 대신 컨트롤러가로드 될 때 미리보기 이미지 생성을 수행하고 적절한 이름을 사용하여 NSArray/NSCache/디스크에 이미지를 저장해야합니다. 그런 다음 cellForRowAtIndexPath이 호출되면 적절한 이미지를 얻습니다.

코드가 닫혀 있다면 파일 이름을 filePathsArray으로 반복하고 실제로는 videoURL을 만듭니다.

몇 개의 스레드가 있는지에 따라 백그라운드 스레드에서이 프로세스를 실행하고 각 스레드가로드 될 때 테이블보기에 새로 고침을 지시 할 수 있습니다.

관련 문제