Background
You may have seen my prior post on this topic: Streaming Media with Android. The title is slightly innacurate as it’s less about generic ‘media’ streaming and instead focused on .mp3 audio. The basic streaming function described in the post is still valid for Android however that post was written when Android was still v1.0. Android’s media handling has improved substantially since then but is still unstable with respect to many media formats. In my experience, it’s best to stick to .mp3 for audio and .3gp for video. The best tool I’ve found for generating .3gp video is Quicktime Pro. Yes…oddly Apple makes the easiest tool for generating video for Android.
Scroll to the bottom to see a few tutorials I’ve found on Live Streaming with Android.
Streaming Media…As In Live Radio
My prior streaming media post has recieved many questions about streaming live audio/video. That type of streaming is completely different from what I previously discussed, but since there’s so much interest, I though I would write a brief post that I can refer people to. To start, here’s the list of Android’s supported media formats. As you can see, Android now supports streaming of these live media formats:
- RTSP (RTP, SDP)
- HTTP/HTTPS progressive streaming
- HTTP/HTTPS live streaming draft protocol:
- MPEG-2 TS media files only
- Protocol version 3 (Android 4.0 and above)
- Protocol version 2 (Android 3.x)
- Not supported before Android 3.0
- Note: HTTPS is not supported before Android 3.1.
Progressive versus Live Streaming
This distinction is important and may or may not be under your control. If you are streaming your own media, then research the strengths and weaknesses of these two options to determine what’s right for you. If your app will play somebody elses content, then you’ll need to determine which format they are using. In general though, if the media to stream is self-contained in a file, then progressive streaming is the easiest solution. If the media is of indeterminate length because it’s being generated or created live (e.g. radio or live video blog), then you’ll need ‘live’ streaming.
Progressive Streaming
File delivery via HTTP is referred to as ‘progressive or http streaming’. This isn’t really file streaming as much as complete download of a media file to the user’s computer but with playback initiated as soon as sufficient content has been downloaded. The media file is buffered onto the user’s computer so it can be viewed/listened to. In technical terms, the initially downloaded file bytes must contain a header describing the media file format, encoding quality (e.g. 128 kbps) and such. The server doesn’t care about the file’s content though, it simply sends data to the app as fast as it can. Because the file is downloaded from in its entirety, the ability to skipping to parts of the file that have not yet been downloaded is not possible…the user must wait for the server to stream all the prior content before playing the selected section.
Code: Progressing Streaming
Go here for the code from my progressive streaming post.
Live Streaming
Live streaming requires the overhead of a streaming server – special software that handles the media requests. This is different from progressive streaming in which a standard web server can simply deliver a media file via HTTP. Live streaming requires a more intelligent conversation between the streaming server and the local app performing media playback. The user’s app must provide ‘control handling’ between itself and the server. These control messages include ‘play’, ‘pause’, and ‘seek’ but also details about the quality of the media to be delivered. E.g. if the app is on a slower network, then it should request lower quality (i.e. kbps) media and if the device has a smaller screen, it would request video for that size to reduce unnecessary bandwidth usage.
The advantages of Live Streaming are the ability to begin playback at any point, skip through the media, more efficiently use bandwidth, and to avoid storing media file on the device (the data is played and discarded immediatley – e.g. the difference between Apple’s 1st and 2nd generation Apple TV).
When selecting your streaming servers, you’ll need to determine the appropriate streaming protocols: RTSP(Real time streaming protocol), RTMP(Real time messaging protocol) and MMS (Microsoft media services). These streaming protocols deliver video well by being more focussed on continuous delivery than 100% accuracy. The assumption is that it’s better to have a momentary glitch rather than stopping media playback altogether.
Code & Tutorials: Live Streaming
CatDaaaady repurposed my progressive streaming code and wrote code to listen to NPR’s streaming broadcast. In his words, “I used Biosopher’s code and modified it to support a continuous stream of audio instead of a file. It downloads X number of seconds and save that audio segment. Then it starts playing that audio clip while it downloads the next sections of audio in the background. Then queuing up the audio segments for playing next. It is not perfect though.
I get a slight playback pause between audio segments though. Hopefully I will prefect it or find another way around.”
And here are a couple posts from other people w/code samples for Live Streaming on Android.
http://justdevelopment.blogspot.com/2009/10/video-streaming-with-android-phone.html



