This is very strange to me…
I have a simple WebView that loads and interacts with the user exactly like safari mobile (iPhone). Now when you visit m.youtube.com in safari, the url changes when you click on a link to something like this…
http://m.youtube.com/watch?gl=US&hl=en&client=mv-google&v=HX6SyoZ5kw8
The problem with this is I don’t think that url is being used in my webview… What do I mean? The following code is used to load a url every time the user try’s to click on a link, and it works, but I have a problem with Youtube…
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSLog(@"%@",urlString);
VideoURLTextBox.text = urlString;
return YES;
}
When I first start up the webview it loads m.youtube.com and NSLogs() it into my console, but when I decide to click on a video it fails to NSLog() therefore I don’t think a new url is being loaded, but when you load m.youtube.com in safari and click on a video you load a url like above, so why does this not NSLog() in my iPhone application?
What your probably seeing is that the youtube video is running javascript to play the video, you’d have to intercept the javascript callbacks to see that. Here’s a link to the youtube video player api, detailing the callbacks, https://developers.google.com/youtube/js_api_reference#SubscribingEvents
If you just want to embed a youtube video in an iOS application then use this.
Using the mobile YouTube site isn’t great, I had lots of problems with it in the past and ended up making a UIWebView category. I came across your question and decided to throw it on github 🙂
https://github.com/enigmaticflare/UIWebView-YouTube–iOS-Category–ARC-compliant-code
UIWebView+YouTube iOS category to simplify loading youtube videos.
Instructions
1) Add these files to your project
2) Initiate UIWebView for example
Good luck, hope this is what your looking for 🙂
Adam