Ios4 如何获取视频列表的缩略图?
我想创建一个表视图来列出所有视频信息。我需要从互联网上获取缩略图像 加载视图时,我请求每个视频的缩略图。但当请求完成时,通知中心将通知所有视频对象。因此,所有表单元格将同时更新图像。最后,所有表格单元格都显示最后完成的相同缩略图 奇怪的是,它在IOS5上运行良好。只有当我在IOS4上运行应用程序时,才会发生这种情况 这是我的密码:Ios4 如何获取视频列表的缩略图?,ios4,ios5,Ios4,Ios5,我想创建一个表视图来列出所有视频信息。我需要从互联网上获取缩略图像 加载视图时,我请求每个视频的缩略图。但当请求完成时,通知中心将通知所有视频对象。因此,所有表单元格将同时更新图像。最后,所有表格单元格都显示最后完成的相同缩略图 奇怪的是,它在IOS5上运行良好。只有当我在IOS4上运行应用程序时,才会发生这种情况 这是我的密码: -(void)viewDidLoad{ dataArray = [[NSMutableArray arrayWithContentsOfFile:[[NSB
-(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;
}
}
}
-(void)viewDidLoad{
dataArray=[[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“plist”]]retain]类型的“视频”;
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(receiveNotification:)名称:MPMoviePlayerThumbnailImageRequestDidFinishNotification对象:nil];
CTLARY=[[NSMUTABLEARY alloc]init];
对于(int i=0;i通常,您不会获取单元格并直接更新它们。建议的方法是更新基础模型(数据源)。然后,调用reloadRowsAtIndexPaths:withRowAnimation:
方法,传递索引路径
然后应使用新值重新绘制单元格
还请注意,顾名思义,模拟器不是模拟器,事实上,它运行的库与物理设备中的库不同。可能会发生偏差,在调试时应非常小心假设