我正在尝试让 YouTube 在我的 iOS 应用程序中运行。我正在成功检索特定用户的视频列表,但我正在努力实现 didSelectRowAtIndexPath 以便将所选视频嵌入到单独的 viewController 中。这是我遇到问题的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
videoArray = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
NSString *tempUrl = [videoArray objectAtIndex:0];
NSLog(@"The URL is:%@",tempUrl);
detailController.videoString = tempUrl;
[self.navigationController pushViewController:detailController animated:YES];
}
每次我运行它时,我都会在'detailController.videoString = tempUrl;'处得到一个断点
我可以看到 tempUrl 字符串正在通过 NSLog 填充以下内容:
The URL is:GDataMediaContent 0x69c76a0: {url:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:1913}
如何从 GData API 中仅提取视频 URL?
提前感谢您的回复。
我进行了以下更改,现在我得到了一个正确的 URL 字符串:
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
NSArray *mediaContents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:mediaContents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
NSLog(@"The URL is:%@",[flashContent URLString]);
detailController.videoString = [flashContent URLString];
这给了我来自 NSLog 的以下信息:
The URL is:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata
但是,我仍然在 'detailController.videoString = [flashContent URLString]; 处获得断点;