MediaPlayer.setDataSource(String) not working with local files

Alternative Solution #1: Using Resources.getIdentifier() Why not use getResources().getIdentifier() to get id of the resource and use the static MediaPlayer.create() as usual? public int getIdentifier (String name, String defType, String defPackage) getIdentifier() takes your resource name (test0), resource type(raw), your package name and returns the actual resource id. MediaPlayer mp; //String filename = “android.resource://” + … Read more

Android MediaPlayer Problems :”Error (-38 , 0) ” and “stop called in state 1”

Before prepare(), you need first to call setDataSource(..). The Media framework is a very strict state machine, and it’s really cumbersome to handle all the different states. I’ve used this little wrapper that makes the coding/debugging a bit easier. You can give it a try. Regarding emulator – note that not all file formats are … Read more

Android: How to integrate a decoder to multimedia framework

In Android SF framework, the codecs are registered through media_codecs.xml. In standard android distribution, an example media_codecs.xml can be found here. All audio-visual components are registered as OMX components. 1. Codec Registration To register your video decoder, you would have to add a new entry under <Decoders> list. To ensure that your codec is always … Read more

MediaPlayer error (1, -1004) aka MEDIA_ERROR_IO trying to stream music on Samsung S3

The answer to this question turned out to be an issue on Android firmware installed on Samsung S III devices running Android 4.1.2. It seemed to have been something relating to the source of the stream, because some sources eventually played on the device, but the one we needed, never played. If you can get … Read more

Android MediaPlayer/VideoView error (1, -2147483648)

As it turns out, error -2147483648 indicates an unknown error. This could have something to do with the video encoding, but it’s also worth checking that the file path exists and that the VideoView has permission to read it. My issue was that I was writing my files with Context.MODE_PRIVATE (the default). openFileOutput(filename, Context.MODE_PRIVATE); This … Read more

Android – play sound on button click – Null pointer exception

Thanks you for your answers! Appreciate it! Here’s how I finally managed to get it work: button[i].setOnClickListener(new OnClickListener() { public void onClick(View view) { mp = MediaPlayer.create(Test.this, R.raw.mysound); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mp.release(); } }); mp.start(); } });

Why does it take so long for Android’s MediaPlayer to prepare some live streams for playback?

It does appear that it is buffering a fixed amount of data rather than a fixed amount of time. For anyone who doesn’t know the bitrates of various types of NPR streams off the top of their head, the data looks like: MPR news stream: 27 seconds (http://newsstream1.publicradio.org:80/), 64 kbps MPR classical music stream: 15 … Read more