• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - youtube 视频的缩略图

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:39:48 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试为 youtube 视频创建缩略图,但出现以下错误:-

Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo=0xa07ac00            NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0xa07e580 "The operation couldn’t   be completed. (OSStatus error -12939.)", NSLocalizedFailureReason=The server is not correctly configured.

请帮我从 youtube 链接创建 youtube 视频的缩略图。

用于创建缩略图的代码如下:-

NSURL *url = [NSURL URLWithString:strVideoURL];

AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;

CMTime thumbTime = CMTimeMakeWithSeconds(0,30);

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error)
{
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    // TODO Do something with the image
    NSLog(@"CGImage---- %@", im);
    UIImage *thumbnail=[UIImage imageWithCGImage:im];

    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(30, 50, 120, 120)];
    imageView.backgroundColor=[UIColor redColor];
    imageView.image=thumbnail;
    [image addSubview:imageView];

    UIView *view=(UIView*)[self.view viewWithTag:10];
    [view removeFromSuperview];
};

CGSize maxSize = CGSizeMake(128, 128);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];



Best Answer-推荐答案


虽然你的问题没有你的任何源代码,所以我不知道你哪里出错了。试试这个,它对我有用。

#define YOUTUBE_URL @"https://gdata.youtube.com/feeds/api/videos?v=2&author=%@&orderby=published"

NSString *userName = @"ipl";
_url = [NSURL URLWithString:[NSString stringWithFormat:YOUTUBE_URL,userName]];

-(void) fetchYoutubeThumbnails {
    NSURLRequest *_request = [[NSURLRequest alloc] initWithURL: _url];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
    [connection start];
}

- (void)connectionNSURLConnection *)connection didReceiveDataNSData *)data {

    [recievedData appendData:data]; //recievedData is a class variable of type NSMutableData
}

- (void)connectionDidFinishLoadingNSURLConnection *)connection {

    NSString *xmlString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
    NSDictionary *result = [XMLReader dictionaryForXMLString:xmlString error:Nil];

    if(result.count > 0) {

        NSMutableArray *items = [[result objectForKey"feed"] objectForKey"entry"];
        for(int i = items.count -1; i >= 0; i--) {
            NSDictionary *item = [items objectAtIndex:i];
            NSString *videoThumbnaulUrl = [[[[item valueForKey"media:group"] valueForKey"media:thumbnail"] objectAtIndex:0] valueForKey"url"];
    // Use this url to get the thumbnail.  

    }
}

关于iphone - youtube 视频的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910712/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap