Goofy
Goofy

Reputation: 6128

Sample 1 not ready - Soundpool in Android 2.1

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.

Upvotes: 4

Views: 6810

Answers (4)

Chirag Patel
Chirag Patel

Reputation: 11508

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();
    }
}

Upvotes: 1

Fran Marzoa
Fran Marzoa

Reputation: 4544

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:

  1. unable to load (null)
  2. sample 1 not ready

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:

  1. The file is not there.
  2. The file is there, but it is not readable for some reason.
  3. The file is there, and it is readable, but it is corrupt or not an audio file.
  4. The file is there, and it is readable, and it is a non corrupted audio file, but SoundPool dislikes it.

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,

Upvotes: 9

AndroidDev
AndroidDev

Reputation: 21

Have you tried calling mediaplayer.release() and re-initilizing? also http://developer.android.com/reference/android/media/MediaPlayer.html

Upvotes: 0

skywall
skywall

Reputation: 4005

I think that's your problem. Whole file is not loaded and you're trying to play it. You have to wait some time before playing it.

Upvotes: 0

Related Questions