我正在尝试为 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];
虽然你的问题没有你的任何源代码,所以我不知道你哪里出错了。试试这个,它对我有用。
#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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |