gpt4 book ai didi

iphone - youtube 视频的缩略图

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:26 26 4
gpt4 key购买 nike

我正在尝试为 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)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

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

- (void)connectionDidFinishLoading:(NSURLConnection *)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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com