0

我正在使用 HCYoutubeParser(https://github.com/hellozimi/HCYoutubeParser)在我的 ios 应用程序中播放一些视频。当我尝试播放一些视频时,它似乎无法播放。

代码如下所示:

- (void)playVideo:(id)sender
{
    if (_urlToLoad)
    {
        MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:_urlToLoad];
        _mp = player;
        [self presentViewController:_mp animated:YES completion:nil];
    }
}

- (void)submitYouTubeURL:(id)sender {

    [playButton setImage:nil forState:UIControlStateNormal];

    NSURL *url = [NSURL URLWithString:_urlOfYoutube];
    activityIndicator.hidden = NO;
    [HCYoutubeParser thumbnailForYoutubeURL:url thumbnailSize:YouTubeThumbnailDefaultHighQuality completeBlock:^(UIImage *image, NSError *error) {

        if (!error) {
            [playButton setBackgroundImage:image forState:UIControlStateNormal];
            playButton.hidden = NO;

            NSDictionary *qualities = [HCYoutubeParser h264videosWithYoutubeURL:url];
            _urlToLoad  = nil;
            _urlToLoad = [NSURL URLWithString:[qualities objectForKey:@"medium"]];
            NSLog(@"%@",[NSURL URLWithString:[qualities objectForKey:@"medium"]]);
            activityIndicator.hidden = YES;

            [playButton setImage:[UIImage imageNamed:@"play_button"] forState:UIControlStateNormal];
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
            [alert show];
        }
    }];
}

给出问题的行是 _urlToLoad = [NSURL URLWithString:[qualities objectForKey:@"medium"]];

[NSURL URLWithString:[qualities objectForKey:@"medium"]] 返回 null..

我该如何解决这个问题?

4

1 回答 1

2

就我而言,我得到 0 键值对

NSDictionary *qualities = [HCYoutubeParser h264videosWithYoutubeURL:url];

即,我得到了qualities0 键值对。

我发现HCYoutubeParser.m在方法中+ (NSDictionary *)h264videosWithYoutubeID:(NSString *)youtubeID的代码没有初始化变量signature变量,所以我替换了 NSString *signature = nil; 和NSString *signature = @"";

于 2014-03-03T13:41:33.503 回答