Recently I’ve been working on an application for a company based near to where I live – part of their application involves some video in the app. Now Android has a 50 meg limit on apk files in the market, so I was tasked with streaming the videos from YouTube, which doesn’t seem to be a massive problem up front.
How wrong I was.
Getting YouTube videos to stream inside an Android app is actually really difficult – I hunted for hours on StackOverflow.com looking for something which would work, only to be given half baked code or ill-thought-out solutions. I got something working by faking the browser agent and loading the video directly, but this would only work in Android 2.x and then only if the user has Flash installed.
So I wrote to my client – telling them that I’d already spent quite a lot of time on this, and that I wanted them to make a call on how best to proceed…and about 30 minutes later I found the answer. Open YouTube Player is a fantastic bit of code, written by Keyes Labs which you can pretty much drop in to your code to get working. It looks like it’s dependant on the way YouTube encodes their videos, so if that changes then it may break, but the project is active on and it’s the best solution I’ve found.
I hope this saves someone else a lot of hunting the internet for a solution to this problem, and a massive thanks to Keyes Labs.