Skip to content Skip to sidebar Skip to footer

Android Media Player Fails Mp3 With Pvmferrnotsupported?

I have a downloaded MP3 that I can verify as MP3 by adb pull to my mac or pc and play in its respective media player. However, the error from Android implies that it does not supp

Solution 1:

FileInputStreamfis= getBaseContext().openFileInput(filename.toString());
mp = newMediaPlayer();
mp.setOnCompletionListener(onCompleteAudioListener);
mp.setDataSource(fis.getFD());
mp.prepare();
mp.start();

Plus normal check and error handling.

Solution 2:

It would be good to check whether the file you want to play exists and its length is greater than 0 just to make sure the path is correct:

Filefile=newFile("/data/...../....mp3");

booleanexists= file.exists();

longlength= file.length();

Also make sure that your URI starts with file://

Solution 3:

OK - I got it to work, but not as I hoped I could implement. First, I had to store in the system media folder:

Filefile=newFile("/system/media/audio/ringtones/", filename);

Second, I had to stop, prepare, start the media player. I tried that based on other postings elsewhere on the web.

if (exists && length > 0) {
                mp = MediaPlayer.create(context, uriMp3);
                mp.stop();
                mp.prepare();
                mp.start();
            } else {
                if (exists) {
                    return String.format("Ringtone has length %d.", length);
                } else {
                    return String.format("Ringtone %s is missing.", uriMp3.toString());
                }
            }

Post a Comment for "Android Media Player Fails Mp3 With Pvmferrnotsupported?"