Iphone UIImageView图像或视频

Iphone UIImageView图像或视频,iphone,video,uiimageview,uiimage,Iphone,Video,Uiimageview,Uiimage,我有一个UIImageView,我把来自url(数据库)的图像放在这里。但有一个问题:有些URL不是图像,而是指向youtube或其他网站的链接。是否可以将视频添加到UIImageView?我怎样才能做到这一点 救命啊!谢谢。UIImageView只能显示图像。但您可以从视频创建拇指图像并显示在imageview中。您可以在数据库端设置标志,如,若url为图像,则设置标志=1;若url为视频,则设置标志=2。或者您可以使用扩展来确定。从url拆分扩展名 您可以从视频中生成拇指图像,如 N

我有一个UIImageView,我把来自url(数据库)的图像放在这里。但有一个问题:有些URL不是图像,而是指向youtube或其他网站的链接。是否可以将视频添加到UIImageView?我怎样才能做到这一点


救命啊!谢谢。

UIImageView只能显示图像。但您可以从视频创建拇指图像并显示在imageview中。您可以在数据库端设置标志,如,若url为图像,则设置标志=1;若url为视频,则设置标志=2。或者您可以使用扩展来确定。从url拆分扩展名

您可以从视频中生成拇指图像,如

    NSURL *videoURl = [NSURL fileURLWithPath:videoPath];
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
    AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    generate.appliesPreferredTrackTransform = YES;
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 60);
    CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];

    UIImage *img = [[UIImage alloc] initWithCGImage:imgRef];
     [YourImageView setImage:img];
    [img release];

UIImageView只能显示图像。如果您可以确定从数据库中获得的URL是您的tube,那么您可以从视频中创建缩略图并在UIImageView中显示它。可能是一些示例代码?Tnx