View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
#BBC IPLAYER #HTML5 VIDEO TAG #IPAD #IPHONE #UIWEBVIEW #USER-AGENT

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

#BBC IPLAYER #HTML5 VIDEO TAG #IPAD #IPHONE #UIWEBVIEW #USER-AGENT

Related Posts

BBC iPlayer - updated sample code - Hey there, just a quick update to let you know I've whipped up a new demo using the RSS feeds from the iPlayer site. It locates URLs and takes advantage of the webview to play the movies out, pretty neat huh? Just a reminder, you'll need the iPhone SDK and tool chain to get this project up and running, and remember, it's a rough around the edges, so use with caution. Be sure to check out the original blog post for more insight. Just a heads up, don't expect to see this app on the iTunes store anytime soon, the BBC might not be too thrilled about it...

Related Videos

Reviving a Broken iPad: Transforming it into a Magic Mirror with Raspberry Pi Zero - Learn how to transform an old iPad 1 screen and a Raspberry Pi Zero into a Magic Mirror with this step-by-step guide! Enhance your home with this unique, DIY upgrade.
Pong on the apple watch - Get a glimpse of a quick demo on playing Pong on the Apple Watch, skillfully hacked together at the iOSDevUK event! Don't miss out!
Streaming Video and Audio over WiFi with the ESP32 - In this video, we dive into a hardware hack combining several components to create my version of the TinyTV, complete with a remote control, and video streaming over Wi-Fi. We challenge the speed of image display, using different libraries and tweaking performance for optimal results. We explore Motion JPEG or MJPEG to decode and draw images quickly, and even reach about 28 frames per second. We also catered audio using 8-bit PCM data at 16kHz, and deal with syncing both video and audio streams. Finally, we add some interactive elements allowing us to change channels and control volumes, with a classic static animation thrown in for good measure. There's a few hiccups along the way, but that's part of the fun, right?
Tanks! for the Palm Pre and Palm Pixie - Witness the successful porting of an iPhone app to a Palm Pre Plus in this intriguing video!
Build Your Own Custom Bluetooth Speaker with ESP32 & A2DP | DIY Audio Project - Learn how to repurpose old iPad speakers with a custom designed stereo I2S Class D amplifier, using EasyEDA for the schematic and PCB layout. Discover how to create a simple Bluetooth speaker using an ESP32 and a stereo amplifier for your DIY audio projects.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

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