如何限制在iOS上无法在美国播放的YouTube视频?

时间:2014-04-22 03:41:15

标签: ios

如何限制无法在美国播放的YouTube视频?

- (void)loadMediaListWithQuery:(NSString *)query
                        offset:(int)offset
                     withBlock:(void (^)(NSMutableArray *mediaArray, NSError *error))block
{
    NSError *searchError = [NSError errorWithDomain:@"No video Found!" code:120 userInfo:NULL];
    query = [query isEqualToString:@""] == TRUE ? defaultSearchQuery : query;

    NSString *searh_url=[NSString stringWithFormat:@"%@?q=%@&orderby=relevance&start-index=%d&max-results=20&v=2&time=all_time&alt=json",youtubeSearhURL,query,offset];

    NSURLRequest *urlReques = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[Utils convertSpaceString:searh_url]]];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
                                         initWithRequest:urlReques];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation
                                               , id responseObject)
     {
         NSError *error=NULL;
         NSMutableArray *mediaArray = [NSMutableArray array];

         NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:responseObject
                                                                 options:NSJSONReadingMutableContainers
                                                                   error:&error];

         NSMutableArray *tempDic=[[jsonDic valueForKey:@"feed"] objectForKey:@"entry"];
         for (int i=0;i < tempDic.count;i++) {
             @autoreleasepool {
                 MediaEntity *post = [[MediaEntity alloc] initDataWithDic:[tempDic objectAtIndex:i]];
                 [mediaArray addObject:post];
             }
         }
         if (block) {
             tempDic.count > 0 ? block(mediaArray,NULL) : block(NULL,searchError);
         }
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         if (block) {
             block(NULL,error);
         }
     }
     ];
    [operation start];
}

1 个答案:

答案 0 :(得分:0)

LBYouTubeView已停产。我不再解决任何问题了。虽然这种方法解决了一些问题,但它不够可靠。看看XCDYouTubeVideoPlayerViewController。它与此项目类似,但似乎效果更好,因为它提取视频网址的方式不那么笨拙。

使用链接https://github.com/larcus94/LBYouTubeView