OStack程序员社区-中国程序员成长平台

标题: iphone - YouTube 视频 GData API [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 13:24
标题: iphone - YouTube 视频 GData API

我正在尝试让 YouTube 在我的 iOS 应用中正常运行。我正在成功检索特定用户的视频列表,但我正在努力实现 didSelectRowAtIndexPath 以便将所选视频嵌入到单独的 viewController 中。这是我遇到问题的代码:

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)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]; 处获得断点;



Best Answer-推荐答案


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

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)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/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4