Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:37:33+00:00 2026-05-24T15:37:33+00:00

On Android 2.2+ there is something called SoundPool.OnLoadCompleteListener allowing to know whether a sound

  • 0

On Android 2.2+ there is something called SoundPool.OnLoadCompleteListener allowing to know whether a sound has been loaded successfully or not.

I am targeting lower API version (ideally 1.6 but could go for 2.1) and I need to know whether a sound has been loaded correctly (as it is selected by the user). What’s the proper way to do it?

I hope not load the sound once with MediaPlayer and if correct with SoundPool?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:37:34+00:00Added an answer on May 24, 2026 at 3:37 pm

    I implemented a kind-of-compatible OnLoadCompleteListener class that works at least for Android 2.1.

    The constructor takes a SoundPool object, and sounds for which the SoundPool.load(..) has been called must be registered with OnLoadCompleteListener.addSound(soundId). After this, the listener periodically attempts to play the requested sounds (at zero volume). If successful, it calls your implementation of onLoadComplete, like in the Android 2.2+ version.

    Here’s a usage example:

        SoundPool mySoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
        OnLoadCompleteListener completionListener = new OnLoadCompleteListener(mySoundPool) {
            @Override
            public void onLoadComplete(SoundPool soundPool, int soundId, int status) {
                Log.i("OnLoadCompleteListener","Sound "+soundId+" loaded.");
            }
        }
        int soundId=mySoundPool.load(this, R.raw.funnyvoice,1);
        completionListener.addSound(soundId);  // tell the listener to test for this sound.
    

    And here’s the source:

    abstract class OnLoadCompleteListener {    
        final int testPeriodMs = 100; // period between tests in ms
    
         /**
         * OnLoadCompleteListener fallback implementation for Android versions before 2.2. 
         * After using: int soundId=SoundPool.load(..), call OnLoadCompleteListener.listenFor(soundId)
         * to periodically test sound load completion. If a sound is playable, onLoadComplete is called.
         *
         * @param soundPool  The SoundPool in which you loaded the sounds. 
         */
        public OnLoadCompleteListener(SoundPool soundPool) {
            testSoundPool = soundPool;
        }
    
        /**
         * Method called when determined that a soundpool sound has been loaded. 
         *
         * @param soundPool  The soundpool that was given to the constructor of this OnLoadCompleteListener
         * @param soundId    The soundId of the sound that loaded
         * @param status     Status value for forward compatibility. Always 0.  
         */
        public abstract void onLoadComplete(SoundPool soundPool, int soundId, int status); // implement yourself
    
         /**
         * Method to add sounds for which a test is required. Assumes that SoundPool.load(soundId,...) has been called.
         *
         * @param soundPool  The SoundPool in which you loaded the sounds. 
         */
        public void addSound(int soundId) {
            boolean isFirstOne;
            synchronized (this) {
                mySoundIds.add(soundId);
                isFirstOne = (mySoundIds.size()==1);
            }
            if (isFirstOne) {
                // first sound, start timer
                testTimer = new Timer();
                TimerTask task = new TimerTask() { // import java.util.TimerTask for this
                    @Override
                    public void run() {
                        testCompletions();
                    }  
                };
                testTimer.scheduleAtFixedRate(task , 0, testPeriodMs);
            }
        }
    
        private ArrayList<Integer> mySoundIds = new ArrayList<Integer>();
        private Timer testTimer;  // import java.util.Timer for this
        private SoundPool testSoundPool;
    
        private synchronized void testCompletions() {
            ArrayList<Integer> completedOnes = new ArrayList<Integer>();
            for (Integer soundId: mySoundIds) {
                int streamId = testSoundPool.play(soundId, 0, 0, 0, 0, 1.0f);
                if (streamId>0) {                   // successful
                    testSoundPool.stop(streamId);
                    onLoadComplete(testSoundPool, soundId, 0); 
                    completedOnes.add(soundId);
                }
            }
            mySoundIds.removeAll(completedOnes);
            if (mySoundIds.size()==0) {
                testTimer.cancel();
                testTimer.purge();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what this is called, but it is something like syncing android
Is there something in the Android developer guidelines that disuades developers from providing the
I know this is the list of permissions in android Is there any new
In an android Activity is there a way to programmatically list the it has
There is something I'm just not getting, and I'm looking for assistance in understanding
I've used an app on the Android called Noom Weight Loss, and it has
When developing on Android we have something called Monkey, it generates random user events
Hey, Im trying something in android, that has to get the words sent in
On Android there's neat way to browse between several pages of data with the
Two question on Bluetooth development on Android: Is there a way to enable Bluetooth

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.