问题描述
我正在开发一个使用UIWebView来显示youtube视频列表的应用.
为了播放视频,我使用了youtube嵌入功能,当用户单击视频缩略图时,它会打开youtube应用程序-效果很好.
I am developing an app that use UIWebView to display a list of videos from youtube.
For playing the videos I use the youtube embed feature and it open the youtube application when the user clicks the video thumbnail - works great.
我希望在单击网络视图上youtube缩略图附近的立即观看"按钮时执行相同的功能,但是当我尝试对youtube视频使用"href"时,它将打开"youtube"播放页面",而不是像嵌入方式那样的youtube iPhone应用程序...
I want the same functionality to be executed when I click a "Watch Now" button that will be located near the youtube thumbnail on my web view but when I try to use "href" to the youtube video it opens the "youtube play page" and not the youtube iPhone application like in the embed way...
有什么想法吗?
Netanel.
推荐答案
我已经创建了一个执行以下代码的测试项目:
I've created a test project with following code executed:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=5ra01Bqef7A"]];
在Simulator中运行项目可以重现您偶然发现的问题:测试应用程序启动了Safari,它只是打开了Youtube视频页面.但是,当我在iPhone上运行相同的项目时,结果却有所不同:它启动了Youtube应用,并立即开始在URL中加载/播放视频.
Running the project in Simulator allowed to reproduced the issue you've stumbled upon: test app launched Safari and it simply opened the Youtube video's page. But when I ran the same project on an iPhone the result was different: it launched the Youtube app and it started lading/playing the video in the URL right away.
相同代码表现不同的原因是模拟器中没有Youtube应用程序,因此其环境中唯一可用的URL处理程序是Safari.因此,一切正常进行,您可以继续开发应用.
The reason why the same code behaves itself differently is that there's no Youtube app in Simulator, so the only URL handler available in its environment is Safari. So everything's working as it should, you can continue developing your app.
顺便说一句,这是Youtube上一个非常不错的官方博客文章,内容是将其与iPhone应用程序集成: YouTube API + iPhone =出色的移动应用
BTW here's a really nice official blog post from Youtube about integrating it with iPhone apps: YouTube APIs + iPhone = Cool mobile apps
这篇关于iPhone SDK-从我的应用程序中启动youtube应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!