2012-01-12 8 views
0

모든 vedio 정보를 나열하는 표보기를 만들고 싶습니다. 인터넷에서 미리보기 이미지를 가져와야합니다.동영상 목록의 미리보기 이미지를 가져 오는 방법은 무엇입니까?

보기가로드되면 각 비디오의 축소판을 요청합니다. 요청이 완료되면 알림 센터에서 모든 비디오 객체에 알립니다. 그래서 모든 테이블 셀은 동시에 이미지를 업데이트 할 것입니다. 결국 모든 테이블 셀은 마침내 끝난 동일한 축소판 이미지를 보여줍니다.

이상한 점은 IOS5에서 잘 작동한다는 것입니다. IOS4에서 앱을 실행할 때만 발생합니다.

-(void)viewDidLoad{ 

    dataArray = [[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"vedio" ofType:@"plist"]] retain]; 

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receiveNotification:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:nil]; 

    ctlArray = [[NSMutableArray alloc] init]; 
    for(int i=0; i<[dataArray count]; i++){ 
     MPMoviePlayerController * vedio = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:[[dataArray objectAtIndex:i]objectForKey:@"url"]]]; 
     //[vedio prepareToPlay]; 
     vedio.shouldAutoplay = NO; 
     vedio.controlStyle = MPMovieControlStyleEmbedded; 

     NSMutableDictionary * data = [NSDictionary dictionaryWithObjectsAndKeys:vedio,@"controller",[NSNumber numberWithInt:i],@"index", nil]; 
     [ctlArray addObject:data]; 
     NSMutableArray * allThumbnails = [NSMutableArray arrayWithObjects:[NSNumber numberWithDouble:2.0],nil]; 
     [vedio requestThumbnailImagesAtTimes:allThumbnails timeOption:MPMovieTimeOptionExact]; 

    } 
...... 
} 

-(void)receiveNotification:(NSNotification *)notify{ 

    id pid = [notify object]; 
    for(int i=0; i<[ctlArray count]; i++){ 

     NSMutableDictionary * o= [NSMutableDictionary dictionaryWithDictionary:[ctlArray objectAtIndex:i]]; 

     if (pid == [o objectForKey:@"controller"]) { 

      NSDictionary * d = [notify userInfo]; 

      if([d objectForKey:@"MPMoviePlayerThumbnailImageKey"] != nil){ 
       UIImage * recvdata = [d objectForKey:@"MPMoviePlayerThumbnailImageKey"]; 
       [o setObject:recvdata forKey:@"image"]; 
       [ctlArray replaceObjectAtIndex:i withObject:o ]; 

       NSIndexPath *durPath = [NSIndexPath indexPathForRow:i inSection:0]; 
       UITableViewCell * cell = [tblV cellForRowAtIndexPath:durPath]; 
       if(cell != nil){ 
        UIImageView* iv = (UIImageView*)[cell viewWithTag:10000]; 
        [iv setImage:recvdata]; 
       } 
      } 
      break; 
     } 
    } 
} 

모든 sugesstion이 appreciate.Thanks 것 :

여기 내 코드입니다!

답변

0

일반적으로 셀을 가져 와서 직접 업데이트하지 마십시오. 권장되는 방법은 기본 모델 (데이터 소스)을 업데이트하는 것입니다. 그런 다음 reloadRowsAtIndexPaths:withRowAnimation: 메서드를 호출하고 인덱스 경로를 전달합니다.

그러면 새 값으로 셀을 다시 그려야합니다.

시뮬레이터는 이름에서 알 수 있듯이 실제로는 에뮬레이터가 아니며 실제로 물리적 장치의 라이브러리와 다른 라이브러리로 실행됩니다. 편차가 발생할 수 있으며 디버깅 할 때 매우 신중해야합니다.

관련 문제