iphone - YouTube 视频 GData API

标签 iphone objective-c ios ipad gdata-api

我正在尝试让 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]; 处遇到断点

最佳答案

我能够解决这个问题。我在两个 ViewController 之间添加了一个 Modal segue,并稍微修改了我的代码。这是添加 segue 后我最终使用的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
    GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
    NSString *title = [[entry2 title] stringValue];
    NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
    GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:contents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
    NSString *tempURL = [flashContent URLString];

    detailController.videoString = tempURL;
    detailController.titleString = title;
    [self.navigationController pushViewController:detailController animated:YES];

}

您可以在此处查看完整的 YouTubeDemo 应用代码: https://gist.github.com/2501684

关于iphone - YouTube 视频 GData API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316397/

相关文章:

iphone - NSSortDescriptor,获取按日期排序的最新 5 条记录

iphone - UIPageViewController : Are methods of the delegate are called in response to gesture-based navigation and orientation changes only

ios - UICollectionViewFlowLayout 中有多个补充 View ?

ios - 为什么 UITextField 作为自定义 UITableViewCell 的 subview 会抑制父 UITableView 的滚动?

ios - iPhone X 的顶部栏高度是多少?

iphone - 如何根据 BOOL 值从其他类隐藏已实现的委托(delegate)方法? - objective-c

ios - 如何从 block 内部修改非局部(全局)变量?

iphone - 增加标签栏项目之一的高度

ios - 从 RAM swift 中删除 View

iphone - 跨类声明错误?