Streaming video on android

Playing streaming MP4 video from a URL is a piece of cake in iPhone, but not the case in android. Firstly you have to create your own activity to play video using MediaPlayer class. It is not difficult because there is sample code in the APIDemo projects in the SDK. However, after success to play it on my Nexus One with OS 2.2, I found that it won't play on my G1 with OS 1.6, with error "sorry,this video is not valid for streaming to this Device.."

To test my MP4 video, I found it play perfectly under any OS version if the file is placed locally. But it won't play when it is streaming through http under OS 1.6-2.1. video with 3GP format play nicely though.

After searching the web, I found that many people got the same problem. Some try to fix it by fetching the video file and recreate it on the fly:

http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming...

The method is okay, but seems not so reliable. So I am going to plan to use 3GP instead of MP4 so that it will support all OS versions. Luckily under the final investigation, I found that weather the MP4 can be streamed or not is depending on how to encoding the file. The file must be "atomized" for the older version of android OS.

I test using handbrake as encoder, with the following setting:

handbrake.jpg

According to handbrake, the use of "Web optimized" is:
"Places the MP4 atoms at the beginning of the file instead of the end - assists with faster start of streaming playback from certain devices but makes changes to the atoms less efficient (metadata, etc.)"

And when I use X.264 is codec, I got blank screen. I guess it is due to compatibility only since Android should support X.264 codec. But anyway, it works if using MPEG-4 as codec.

Now the video plays smoothly under streaming using the MediaPlayer class.

You may find the relevant settings on other encoders.