2012-01-12 10 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:メソッドを呼び出します。

新しい値でセルを再描画する必要があります。

また、名前が示すように、シミュレータはエミュレータではなく、実際には物理デバイス内のライブラリとは別のライブラリから実行されていることにも注意してください。偏差が発生する可能性があります。また、デバッグ時には前提に非常に注意する必要があります。

関連する問題