iphone - youtube 视频的缩略图
<p><p>我正在尝试为 youtube 视频创建缩略图,但出现以下错误:-</p>
<pre><code>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.
</code></pre>
<p>请帮我从 youtube 链接创建 youtube 视频的缩略图。</p>
<p>用于创建缩略图的代码如下:-</p>
<pre><code>NSURL *url = ;
AVURLAsset *asset=[ initWithURL:url options:nil];
AVAssetImageGenerator *generator = [ 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=;
UIImageView *imageView=[ initWithFrame:CGRectMake(30, 50, 120, 120)];
imageView.backgroundColor=;
imageView.image=thumbnail;
;
UIView *view=(UIView*);
;
};
CGSize maxSize = CGSizeMake(128, 128);
generator.maximumSize = maxSize;
] completionHandler:handler];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>虽然你的问题没有你的任何源代码,所以我不知道你哪里出错了。试试这个,它对我有用。</p>
<pre><code>#define YOUTUBE_URL @"https://gdata.youtube.com/feeds/api/videos?v=2&author=%@&orderby=published"
NSString *userName = @"ipl";
_url = ];
-(void) fetchYoutubeThumbnails {
NSURLRequest *_request = [ initWithURL: _url];
NSURLConnection *connection = [ initWithRequest:_request delegate:self];
;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
; //recievedData is a class variable of type NSMutableData
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *xmlString = [ initWithData:recievedData encoding:NSUTF8StringEncoding];
NSDictionary *result = ;
if(result.count > 0) {
NSMutableArray *items = [ objectForKey:@"entry"];
for(int i = items.count -1; i >= 0; i--) {
NSDictionary *item = ;
NSString *videoThumbnaulUrl = [[[ valueForKey:@"media:thumbnail"] objectAtIndex:0] valueForKey:@"url"];
// Use this url to get the thumbnail.
}
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - youtube 视频的缩略图,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18910712/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18910712/
</a>
</p>
页:
[1]