guys i have a audio file which i am reading from sdcard it.On click of a button i am playing the audio file from sdcard.It successfully plays the audio file for 6 to 7 times but after that it shows unable to load (null) sample 1 not ready
i am working in Android 2.1 i.e., API 7.
String path="/sdcard/var/audio.mp3"
sound1 = mSoundPool.load(path,1);
mSoundPool.play(sound1, 1, 1, 1, time - 1, 1);
What is soundpool indicating me by saying unable to load (null) sample 1 not ready? How can i fix this please help me i am struggling fro long time.
You will need to check file is loaded successfully before playing it using SoundPool.setOnLoadCompleteListener
public void loadSound (String strSound, int stream) {
boolean loaded = false;
mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
mSoundPool.play(stream, streamVolume, streamVolume, 1, LOOP_1_TIME, 1f);
}
});
try {
stream= mSoundPool.load(aMan.openFd(strSound), 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have had similar problem with a wav file. Let's start discarding some things:
It is NOT a problem of waiting, although it may be in another cases. Please note that you have posted two DIFFERENT error messages like it were one:
The first error is raised when you try to load the sample into the SoundPool, the second one when you try to play it. But in this case the second error is clearly a consequence of the first one: the sample could not be ready if it has not been loaded.
So you should concentrate before in the first error.
It is NOT related to MediaPlayer neither, since you are using the SoundPool that is a different thing AFAIK.
So the source of the problem may be, and should be discarded by order:
This last was my case. For some reason SoundPool were unable to load a wav sample that in fact works in every other player that I have used. So I simply ended using another file with a different format. Here is the format of the offending file, as told by mplayer on my GNU/LiNUX box:
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 96000 Hz, 1 ch, s16le, 1536.0 kbit/100.00% (ratio: 192000->192000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
And here it is the one for the other file that does work:
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 22050 Hz, 2 ch, s16le, 705.6 kbit/100.00% (ratio: 88200->88200)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
There are many differences, but the point is that the second works, so I simply discarded the first one and move into the second. Knowing this if I needed the first sound sample, I just need to adjust its rate and channels with an audio editor like Audacity to solve the problem.
Why it did not just work in first case? Who knows, but if I can solve it so easy... who cares at all?
Regards,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With