views:

1269

answers:

2

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.

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...

Any ideas?

Netanel.

A: 

Hello Inetanel!

I've created a test project with following code executed:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=5ra01Bqef7A"]];

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.

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.

BTW here's a really nice official blog post from Youtube about integrating it with iPhone apps: YouTube APIs + iPhone = Cool mobile apps

Ivan Karpan
A: 

Hello,

I have tried the embed tag in web applications and it works great on the iphone. Now I hope to try it in an iPhone App.

The big problem that I am thinking is:

  • How to play multiple videos one after the other.
  • Using html to display a list of videos in an iPhone App may not look great, as compared to generic App code.

Any ideas on how to get by these. Does NSURL approach solve the problems really becasue I would prefer that.

Thanks, Rajendra.

Rajendra