菜鸟教程小白 发表于 2022-12-12 14:39:48

iphone - youtube 视频的缩略图


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

<pre><code>Error Domain=AVFoundationErrorDomain Code=-11850 &#34;Operation Stopped&#34; UserInfo=0xa07ac00            NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0xa07e580 &#34;The operation couldn’t   be completed. (OSStatus error -12939.)&#34;, 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(@&#34;couldn&#39;t generate thumbnail, error:%@&#34;, error);
    }
    // TODO Do something with the image
    NSLog(@&#34;CGImage---- %@&#34;, 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 @&#34;https://gdata.youtube.com/feeds/api/videos?v=2&amp;author=%@&amp;orderby=published&#34;

NSString *userName = @&#34;ipl&#34;;
_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 &gt; 0) {

      NSMutableArray *items = [ objectForKey:@&#34;entry&#34;];
      for(int i = items.count -1; i &gt;= 0; i--) {
            NSDictionary *item = ;
            NSString *videoThumbnaulUrl = [[[ valueForKey:@&#34;media:thumbnail&#34;] objectAtIndex:0] valueForKey:@&#34;url&#34;];
    // 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]
查看完整版本: iphone - youtube 视频的缩略图