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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:54+00:00 2026-06-01T20:03:54+00:00

I am trying to use the SoundManager to randomly play a 30 second sound

  • 0

I am trying to use the SoundManager to randomly play a 30 second sound bite while simultaneously starting an animation sequence (flashing graphic) triggered by an onTouch event. For whatever reason, the sound bite is clipped after about 5 seconds of playback and I can’t figure out why. Any thoughts?

Also after testing, it appears that the will not play until a minute or so after the initial onTouch event.

public class Soundboard extends Activity {
    private SoundManager mSoundManager;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mSoundManager = new SoundManager();
        mSoundManager.initSounds(getBaseContext());
        mSoundManager.addSound(0, R.raw.sound0);
        mSoundManager.addSound(1, R.raw.sound1);
        mSoundManager.addSound(2, R.raw.sound2);
        mSoundManager.addSound(3, R.raw.sound3);
    };

    public boolean onTouchEvent(MotionEvent evt){

        Random r = new Random();
        int x = r.nextInt(3);

        switch (evt.getAction()) 
        {
            case MotionEvent.ACTION_DOWN:
            mSoundManager.playSound(x);
            startAnimating();
            return super.onTouchEvent(evt);

            case MotionEvent.ACTION_UP:
            break;
            default:
            break;
        }
        return true;
    }

    private void startAnimating() {

        ImageView wiub_screen01 = (ImageView) findViewById(R.id.wiub_screen01);
        Animation fadein01 = AnimationUtils.loadAnimation(this, R.anim.fade_in01);
        wiub_screen01.startAnimation(fadein01);

        ImageView wiub_screen00 = (ImageView) findViewById(R.id.wiub_screen00);
        Animation fadein00 = AnimationUtils.loadAnimation(this, R.anim.fade_in00);
        wiub_screen00.startAnimation(fadein00);
    }

}

  • 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-01T20:03:54+00:00Added an answer on June 1, 2026 at 8:03 pm

    There’s a good chance that the audio hasn’t been loaded. If you really want to play a number of short clips, definitely look at SoundPool instead. (Adapted from Google SoundPool Example)

    Try this:

    public class Soundboard extends Activity {
        private SoundPool mSoundPool;
        boolean loaded = false;
        private int[] soundIDs;
        private int[] resIDs;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
    
            mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
            mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                @Override
                public void onLoadComplete(SoundPool soundPool, int sampleId,
                                int status) {
                        loaded = true;
                }
            });
            resIDs = new int[]{R.raw.sound0,R.raw.sound1,R.raw.sound2.R.raw.sound3 };
    
            for(int i=0; i<resIDs.length; i++){
                soundIDs[i] = mSoundPool.load(this, resIDs[i], 1);              
            }
        };
    
        public boolean onTouchEvent(MotionEvent evt){
    
            Random r = new Random();
            int x = r.nextInt(resIDs.length);
    
            switch (evt.getAction()) 
            {
                case MotionEvent.ACTION_DOWN:
                    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
                    float actualVolume = (float) audioManager
                                    .getStreamVolume(AudioManager.STREAM_MUSIC);
                    float maxVolume = (float) audioManager
                                    .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
                    float volume = actualVolume / maxVolume;
                    // Is the sound loaded already?
                    if (loaded) {
                            mSoundPool.play(soundIDs[x], volume, volume, 1, 0, 1f);
                            Log.i("Test", "Played sound");
                    }
                startAnimating();
                return super.onTouchEvent(evt);
    
                case MotionEvent.ACTION_UP:
                break;
                default:
                break;
            }
            return true;
        }
    
        private void startAnimating() {
    
            ImageView wiub_screen01 = (ImageView) findViewById(R.id.wiub_screen01);
            Animation fadein01 = AnimationUtils.loadAnimation(this, R.anim.fade_in01);
            wiub_screen01.startAnimation(fadein01);
    
            ImageView wiub_screen00 = (ImageView) findViewById(R.id.wiub_screen00);
            Animation fadein00 = AnimationUtils.loadAnimation(this, R.anim.fade_in00);
            wiub_screen00.startAnimation(fadein00);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying use a javascript function while passing php variables in it. For
I am trying use a javascript function while passing php variables in it. For
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
Hi I'm trying use a datepicker on a field I have. I'm trying to
I am need paint my image. I'm trying use JQuery in here this link:

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.