Take the 2-minute tour ×

I have changed the default media framework in Android from Stagefright to Gstreamer. This has been done to make it flexible for our project.

But when I run some apks, all the sounds of the app is getting played at the time of app start, and it does not play after that showing the error "sample # not READY" from Soundpool. For example in an App Baby piano, the sounds of the piano syllables are getting played when I start the application and when I actually click on the piano after entering into the play mode, it is not getting played.

The problem I think is that when the sounds are being loaded into the Soundpool, the Gstreamer Mediaplayer object is created and it gets played and it is being done at the start of the App.

In the log it is showing, Sample Channel Count(0) out of range. It is happening from the SoundPoool.cpp file from the section below.

status_t Sample::doLoad() {
    uint32_t sampleRate;
    int numChannels;
    int format;
    sp<IMemory> p;
    LOGW("Start decode");
    if (mUrl) {
        p = MediaPlayer::decode(mUrl, &sampleRate, &numChannels, &format);
    } else {
        p = MediaPlayer::decode(mFd, mOffset, mLength, &sampleRate, &numChannels, &format);
        LOGW("close(%d)", mFd);
        mFd = -1;
    if (p == 0) {
        LOGE("Unable to load sample: %s", mUrl);
        return -1;
    LOGW("pointer = %p, size = %u, sampleRate = %u, numChannels = %d",
            p->pointer(), p->size(), sampleRate, numChannels);

    if (sampleRate > kMaxSampleRate) {
       LOGE("Sample rate (%u) out of range", sampleRate);
       return - 1;

    if ((numChannels < 1) || (numChannels > 2)) {
        LOGE("Sample channel count (%d) out of range", numChannels);
        return - 1;

    //_dumpBuffer(p->pointer(), p->size());
    uint8_t* q = static_cast<uint8_t*>(p->pointer()) + p->size() - 10;
    //_dumpBuffer(q, 10, 10, false);

    mData = p;
    mSize = p->size();
    mSampleRate = sampleRate;
    mNumChannels = numChannels;
    mFormat = format;
    mState = READY;
    return 0; }

and the MediaPlayerService decode function returns all the values as null from the code section below

sp<IMemory> MediaPlayerService::decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat)
    LOGD("decode(%d, %lld, %lld)", fd, offset, length);
    sp<MemoryBase> mem;
    sp<MediaPlayerBase> player;

    player_type playerType = getPlayerType(fd, offset, length);
    LOGD("player type = %d", playerType);

    // create the right type of player
    sp<AudioCache> cache = new AudioCache("decode_fd");
    player = android::createPlayer(playerType, cache.get(), cache->notify);
    if (player == NULL) goto Exit;
    if (player->hardwareOutput()) goto Exit;


    // set data source
    if (player->setDataSource(fd, offset, length) != NO_ERROR) goto Exit;


    LOGD("wait for prepare");
    if (cache->wait() != NO_ERROR) goto Exit;


    LOGD("wait for playback complete");

    mem = new MemoryBase(cache->getHeap(), 0, cache->size());
    *pSampleRate = cache->sampleRate();//Nes
    *pNumChannels = cache->channelCount();
    *pFormat = cache->format();

    LOGD("return memory @ %p, sampleRate=%u, channelCount = %d, format = %d", mem->pointer(), *pSampleRate, *pNumChannels, *pFormat);

    if (player != 0) player->reset();
    return mem;

The samplerate, channels etc have value 0 getting returned from this function.

After this when the samples are played, it is showing the error ""sample # not READY"

int SoundPool::play(int sampleID, float leftVolume, float rightVolume,
        int priority, int loop, float rate)
    LOGW("sampleID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f",
            sampleID, leftVolume, rightVolume, priority, loop, rate);
    sp<Sample> sample;
    SoundChannel* channel;
    int channelID;

    // scope for lock
        Mutex::Autolock lock(&mLock);

        // is sample ready?
        sample = findSample(sampleID);
        if ((sample == 0) || (sample->state() != Sample::READY)) {
            LOGW("  sample %d not READY", sampleID);
            return 0;


        // allocate a channel
        channel = allocateChannel(priority);

        // no channel allocated - return 0
        if (!channel) {
            LOGW("No channel allocated");
            return 0;

        channelID = ++mNextChannelID;

    LOGW("channel state = %d", channel->state());
    channel->play(sample, channelID, leftVolume, rightVolume, priority, loop, rate);
    return channelID;

Is there a solution for this problem..Plz help..

share|improve this question
Post logs and relevant code sections. –  Michael Dec 21 '12 at 7:59
@Michael I have slightly modified the question and added the code sections also. –  Andriod_user Dec 27 '12 at 5:46

3 Answers 3

Sample not ready usually indicates that it hasn't been loaded yet, i.e. it's still loading. (Perhaps the framework you switched to might be loading it for a longer time.)

You should subscribe to its onLoadCompleteListener, and when you receive the callback, the sound is ready to be played. Before that point, it won't be playable.

share|improve this answer

You can use this methode also

public void loadSound (String strSound, int stream) {
     boolean loaded = false;
     mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            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
share|improve this answer

I had the same problem for android 2.0 and solved by using the .ogg format instead of .mp3 format for the sounds i use as it is mentioned here. I hope this solves your problem.

share|improve this answer

Your Answer


