Members
Syndication
Friends
The latest free ringtones for mobiles.
Latest Comments
This domain is for sale! Please contact me via contact page!
| Android Streaming MediaPlayer Tutorial – Updated to v1.5 (Cupcake) |
|
|
|
|
After spending the last year game programming on the iPhone, I’ve finally returned to Android. My six prior tutorials were outdated (Android v1.0) so I took the time to update them to v1.5 (Cupcake). The most popular of those tutorials was the Streaming MediaPlayer tutorial so that’s the primary focus of this post.
At the time of initially writing the streaming tutorial, Android’s media streaming function didn’t work well so I wrote my own. As of v1.5 however, Android’s MediaPlayer streams very well. That said, it’s still useful to know how to retrieve a media file from a server and store it on the device. This would be useful to immediate replay of the file at a later date or for caching files for later playback ‘off the grid’. Download the source files to get started immediately and then view the rest of the tutorial after the jump.
You may want to look at my old Android v1.0 streaming tutorial for additional details. I don’t want to rewrite that post completely so I’ll mostly focus here on the changes required for Android v1.5. That said, there is very little difference between my old tutorial and this new one. The most important change is that MediaPlayer.setDataSource() now takes a FileDescriptor instead of a String path to the media File. It seems the reason to use FileDescriptors is for security/permission reasons. In either case though, passing a String path to our media File resulted in errors such as “PVMFErrNotSupported” and “Prepare failed.: status=0×1″. So until I learn otherwise, I recommend using FileDescriptor for the MediaPlayer.
The only other change is I can no longer find any File move functionality it Android so I wrote my own. It does exactly what it says, it moves data in one File to a new File location. This is used while streaming the media file so we can double buffer it. The double buffering allows us to simulaneously download to one File while playing from another File. We sync the downloaded data between the Files as more data is downloaded:
Download the source files for all the tutorials. The streaming media tutorial available by clicking button #3. Don’t forget to look at my old Android v1.0 streaming tutorial for additional details.
Source: pocketjourney blog |
Subscribe to this Feed



Three new Samples: T...
resources - Hi there, before, thanks ...
How to display a JPG...
Is that posible to zoom in and drag p...
Making a custom Andr...
Cool - I will use it carefully i promise
How to display a JPG...
problem in image loading - i have exe...
Introducing Calculon...
Thank You for your contribution - Hi,...