View All Posts

(UPDATE - there’s a new sample project available here).

Flew back from the US on Monday carrying a shiny new iPad. One of my thoughts when I bought it was that it would make the perfect device for watching BBC iPlayer in bed - so you can imagine my dissappointment when I found that the iPlayer website kept asking me to install flash to play anything!

The weird thing is, iPlayer works on iPhones - you can even run iPhone apps that contain embedded UIWebViews, surf to the iPlayer web site and it all works!

Seems like it should be possible to get it working on the iPad. First step is to convince the bbc iPlayer website that the iPad is actually an iPhone so that it will give us the mobile website along with mp4 videos instead of flash.

Turns out that this is actually a bit tricky. Changing the User-Agent header field on the device is not exposed from any settings. So we need to create an iPad app with an embedded UIWebView. This will let us change the user agent to whatever we want.

It turns out that this is also a bit tricky. Fortunately there's a comprehensive post on how to do this here: "Changing the headers for UIWebKit HTTP requests".

If you follow the instructions in that link and set the user agent to "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3" you can point your UIWebView to the bbc iplayer web site and get the iPhone compatible website.

Next problem is actually getting the video to play. The iPlayer website uses the "embed" tag for it's videos - this does not seem to play nicely on the iPad. To play a video we need to replace the embed tag with a proper html5 video tag.

Here's some simple code to do this - not the most elegant coding, but it's a quick hack to get something up and running:

```objc -(void) webViewDidFinishLoad:(UIWebView *)webView { NSString *js=@"document.getElementsByTagName(\"embed\").length;"; NSString *embedCountStr=[webView stringByEvaluatingJavaScriptFromString:js]; if(embedCountStr && embedCountStr.length>0) { int embedCountStr=[res intValue]; if(embedCountStr>0) { NSString *videoUrl=[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(\"embed\")[0].getAttribute(\"href\");"]; NSLog(@"%@", videoUrl); [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.write(\"\");", self.view.bounds.size.width, self.view.bounds.size.height, videoUrl]]; } } } ```

This code will find the embed tag on the page, pull out the video url from the href attribute and then write a video tag to UIWebView.

All in all it works pretty well. I've got pretty much full screen video working, device rotation all works. All it needs is a bit of tidying up and error checking.

Hopefully the bbc will update their iPlayer web code to support the iPad - but since it's not scheduled for release in the UK for some time I'd imagine they aren't in any hurry.

Obviously all this is only possible if you have access to the iPhone SDK and can build an application.

Blog Logo

Chris Greening


> Image


A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts