我正在使用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 ..
我该如何解决这个问题?
答案 0 :(得分:1)
在我的情况下,我得到
的0键值对NSDictionary *qualities = [HCYoutubeParser h264videosWithYoutubeURL:url];
是的,我得到qualities
有0个键值对。
我发现HCYoutubeParser.m
中的代码,方法+ (NSDictionary *)h264videosWithYoutubeID:(NSString *)youtubeID
中的变量signature
变量未被初始化,因此我替换了NSString * signature = nil;与NSString *signature = @"";