2010年7月后你如何在iPhone上播放YouTube视频?

时间:2010-10-13 23:59:26

标签: iphone

有一种官方方式可以从YouTube人员那里做到这一点。

  

(链接到YT官方方式 - NB:现在   坏了,但YT没有(打扰)纠正这个页面:   http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

2010年7月,他们故意删除了 - 它不再有用(我有一个在更改前工作正常的应用程序,现在没有,使用YT自己的代码)。

有一种“新”方式,YouTube人称之为“实验性” - 但它只是部分有效。你之前可以把YT视频放到你的iPhone GUI中,现在你不能 - 他们被“要求”给自己整个屏幕。

  

(链接到YT官方“新”方式:   http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html

     

(链接到YT官方帖子,结束   用“它可能会起作用......最终”:   http://code.google.com/apis/youtube/forum/discussion.html?place=topic%2Fyoutube-api-gdata%2FtMYvulpGUow%2Fdiscussion

更糟糕的是,YouTube工程师没有提供任何用户反馈;当用户单击按钮时,您必须等待YT服务器处理几个Web查找(如果查看控制台日志文件,可以看到这一点)。

所有用户看到的是:“此应用似乎已崩溃”。

哎呀!还有其他方法吗?在OS 3.x + 4.x上使用仍然的其他人还有什么 - 因为最近的YT发生了变化?

1 个答案:

答案 0 :(得分:0)

我目前使用与此类似的代码将YouTube视频嵌入到应用中。但是,当用户点击视频(生成用户可以在网页浏览中点按的缩略图)时,它会全屏显示,因此可能不是您要查找的内容。

NSMutableString* urlString = [NSMutableString stringWithFormat:@"http://gdata.youtube.com/feeds/api/videos/%@?v=2&alt=jsonc", youtubeId];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Extract JSON from data into an NSDictionary
NSDictionary* jsonDict = /* however you want to do it */
// Make sure that the video hasn't been flagged as restricted, otherwise the user won't know what's going on. Later check restricted and present an error as appropriate.
BOOL restricted = youtubeVideoRestricted(jsonDict);

如果restrictedNO,那么我会向网页视图提供一些像这样的HTML:

embedSrc = @"<object width=\"640\" height=\"385\">"
            "<param name=\"movie\" value=\"http://www.youtube.com/v/%@\"></param>"
            "<embed src=\"http://www.youtube.com/v/%@\" type=\"application/x-shockwave-flash\" width=\"640\" height=\"385\"></embed>"
            "</object>";
embedSrc = [NSString stringWithFormat:embedSrc, youtubeId, youtubeId];

我现在在商店的应用程序中有这个,工作正常。也就是说,我已经学会了保持视频。因此,如果youtube Feed出现问题,它将回退到视频所在的blip.tv服务。用户在youtube上没有注意到某些内容失败。但这超出了你的问题的范围。