我正在使用 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..
我该如何解决这个问题?