모든 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 것 :
여기 내 코드입니다!