I use MediaPlayers in the most basic way possible, and yet it either
works or not and there is no means to troubleshoot.
I am trying to play a .wav file in my app's own filespace.
It just won't do it. I try variation upon variation.
I suspect that the MediaPlayer boasts only a limited set of WAV file
formats that it can play, but where do I turn to find that, and will
it vary by phone model?
File file = new File(fname);
long siz = file.length();
boolean readable = file.canRead();
// this shows that the file is readable and sized around 60K
// it is a mono 16 bit PCM WAV at 11,025 sample rate
Log.d(TAG, "file is readable=" + readable + ", size=" + siz);
Uri uri = Uri.fromFile(file);
// this create() returns NULL
// the following hard-to-find error is printed:
/*
01-06 18:05:02.257: ERROR/PlayerDriver(51): Command
PLAYER_SET_DATA_SOURCE completed with an error or info
PVMFErrNotSupported
01-06 18:05:02.257: ERROR/MediaPlayer(1917): error (1, -4)
*/
MediaPlayer mp = MediaPlayer.create(getBaseContext(), uri);
mp.start();
This is the code that generated the file:
ByteArrayOutputStream baos; // this is what stores raw audio data to
be written out
try {
OutputStream out = new FileOutputStream(fname);
try {
byte[] pcm = baos.toByteArray();
WaveHeader hdr = new WaveHeader(WaveHeader.FORMAT_PCM,
(short)1, mSampleRate, (short)16, pcm.length);
hdr.write(out);
out.write(pcm);
} finally {
out.close();
}
} finally {
baos.close();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en