Load YouTube GData feed for a single video by id(按 ID 加载单个视频的 YouTube GData 提要)
问题描述
我正在尝试在 UIWebView 中播放 youtube 视频,而不是离开我的应用程序.
I am trying to play a youtube video in a UIWebView instead of leaving my application.
Google 认为这很容易 - http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
Google thinks is easy peasy- http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
所以我的 GData 框架和标头运行良好,而且我在查询、加载用户的视频源等方面没有问题.
So I have the GData framework and headers working nicely, and I have no problem doing queries, loading user's video feeds etc.
但我似乎无法加载特定视频的供稿.我提前知道我想要订阅源的视频的 ID.如何加载特定视频的供稿?
But what I can't seem to do is load a specific video's feed. I know the ids of the videos that I want the feeds for in advance. How do i load a specific video's feed?
然后我将按照 google 的说明进行操作:
I'm then going to follow google's instruction :
Grab the video url from the media tag in the API response with the application/x-shockwave-flash type.
然后像这样嵌入它:
// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.
NSString *htmlString = @"<html><head>
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no, width = 212"/></head>
<body style="background:#F00;margin-top:0px;margin-left:0px">
<div><object width="212" height="172">
<param name="movie" value="http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM"
type="application/x-shockwave-flash" wmode="transparent" width="212" height="172"></embed>
</object></div></body></html>";
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];
任何帮助将不胜感激!
推荐答案
给定 YouTube 视频条目的提要,您可以通过以下方式从每个条目中获取 ID 和 Flash URL:
Given a feed of YouTube video entries, you can get the IDs and Flash URLs from each entry this way:
for (GDataEntryYouTubeVideo *videoEntry in [feed entries]) {
GDataYouTubeMediaGroup *mediaGroup = [videoEntry mediaGroup];
NSString *videoID = [mediaGroup videoID];
NSArray *mediaContents = [mediaGroup mediaContents];
GDataMediaContent *flashContent =
[GDataUtilities firstObjectFromArray:mediaContents
withValue:@"application/x-shockwave-flash"
forKeyPath:@"type"];
NSLog(@"video ID = %@, flash content URL = %@",
videoID, [flashContent URLString]);
}
这篇关于按 ID 加载单个视频的 YouTube GData 提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:按 ID 加载单个视频的 YouTube GData 提要
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01