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 8652331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:17:04+00:00 2026-06-12T14:17:04+00:00

I like the Android Soundpool class for its simplicity and it works well with

  • 0

I like the Android Soundpool class for its simplicity and it works well with the standard audio files I am using in my app. Now I want to make it possible for the user to specify certains sounds by specifying audio files on the sd card. Unfortunately I run into limitations of Soundpool, when the sound file is too big i get a

AudioFlinger could not create track. status: -12

response. It seems I have to switch to MediaPlayer yet before getting into the complexity of MediaPlayer again I wanted to ask if there is an audio library available for android which

  • has the simplicity of Soundpool for playing various sounds
  • doesnt have the limitations of Soundpool regarding the size of the files.

Thank you very much.

martin

  • 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-06-12T14:17:05+00:00Added an answer on June 12, 2026 at 2:17 pm

    For now I came up with a very simple AudioPool class which plays audio added to it subsequently with the MediaPlayer class. This implementation is for sure not mature yet I just thought to share it as it at least gives some idea how this can be approached easily. If you see any problems with this class please let us know.

    Usage:

     AudioPool ap = new AudioPool();
    
     File root = Environment.getExternalStorageDirectory() ;
    
     int id1 = ap.addAudio(root + "/gong1.mp3");
     int id2 = ap.addAudio(root + "/gong2.mp3");
     int id3 = ap.addAudio(root + "/gong3.mp3"); 
    
     ap.playAudio(id1);
     ap.playAudio(id3);
     ap.playAudio(id3);
     ap.playAudio(id2);
    

    which will play gong1 -> gong3 -> gong3 -> gong1 subsequently. As this is basically what I need I leave it here …

    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.Map;
    
    import android.media.MediaPlayer;
    import android.media.MediaPlayer.OnCompletionListener;
    import android.util.Log;
    
    public class AudioPool {
    
    static String TAG = "AudioPool";
    
    MediaPlayer mPlayer;
    
    int mAudioCounter;
    
    int mCurrentId;
    
    HashMap<Integer, String> mAudioMap;
    
    LinkedList<Integer> mAudioQueue;
    
    public AudioPool() {
    
        mAudioMap = new HashMap<Integer, String>();
        mAudioQueue = new LinkedList<Integer>();
        mAudioCounter = 0;
    
    }
    
    public int addAudio(String path) {
        Log.d(TAG, "adding audio " + path + " to the pool");
    
        if (mAudioMap.containsValue(path)) {
            return getAudioKey(path);
        }
        mAudioCounter++;
        mAudioMap.put(mAudioCounter, path);
        return mAudioCounter;
    }
    
    public boolean playAudio(int id) {
    
        if (mAudioMap.containsKey(id) == false) {
            return false;
        }
    
        if (mPlayer == null) {
            setupPlayer();
        }
    
        if (mPlayer.isPlaying() == false) {
            return prepareAndPlayAudioNow(id);
        } else {
            Log.d(TAG, "adding audio " + id + " to the audio queue");
    
            mAudioQueue.add(id);
        }
        return true;
    }
    
    public Integer[] getAudioIds() {
        return (Integer[]) mAudioMap.keySet().toArray(
                new Integer[mAudioMap.keySet().size()]);
    }
    
    public void releaseAudioPlayer() {
        if (mPlayer != null) {
            mPlayer.release();
            mPlayer = null;
        }
    }
    
    
    private boolean prepareAndPlayAudioNow(int id) {
        mCurrentId = id;
        try {
            Log.d(TAG, "playing audio " + id + " now");
            mPlayer.reset();
            mPlayer.setDataSource(mAudioMap.get(id));
            mPlayer.prepare();
            mPlayer.start();
            return true;
        } catch (Exception e) {
            Log.d(TAG, "problems playing audio " + e.getMessage());
            return false;
        }
    }
    
    private boolean playAudioAgainNow() {
        try {
            mPlayer.seekTo(0);
            mPlayer.start();
            return true;
        } catch (Exception e) {
            Log.d(TAG, "problems playing audio");
            return false;
        }
    }
    
    private void setupPlayer() {
        mPlayer = new MediaPlayer();
        mPlayer.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                audioDone();
            }
        });
    }
    
    private void audioDone() {
    
        if (mAudioQueue.size() > 0) {
            Log.d(TAG, mAudioQueue.size() + " audios in queue");
            int nextId = mAudioQueue.removeFirst();
    
            if (mCurrentId == nextId) {
                playAudioAgainNow();
            } else {
                prepareAndPlayAudioNow(nextId);
            }
    
        } else {
            releaseAudioPlayer();
        }
    }
    
    private int getAudioKey(String path) {
        for (Map.Entry<Integer, String> map : mAudioMap.entrySet()) {
            if (map.getValue().compareTo(path) == 0) {
                return map.getKey();
            }
        }
        return -1;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to menu like android default gallery app share option.how do this menu
I want to build a MouseDragScrolling like Android over Java for a big touch
How do I make the settings navigation for SwitchReference like Android native settings app?
I'm looking for an intent-filter, like android.intent.category.HOME, that will allow an app to launch
I am making an app like the Android market where all free app will
I want to create simple application like android image gallery but I don't want
In my Android app I use a TabWidget without any special customization. I'd like
Looking at Android samples, I see different size definitions int .xml layout files, like:
can any view have its layout width in % like android:layout_width=50% as we provide
For my Android app I would like background music. It doesn't have to go

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.