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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:28:07+00:00 2026-05-29T09:28:07+00:00

How to play audio file one after the other without using OncompletionListener(); here is

  • 0

How to play audio file one after the other without using OncompletionListener();

here is my code:

mp.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                i = i + 1;
                System.out.println("" + audio.length);
                if(i < audio.length){
                    img.setImageResource(image[i]);
                    try {
                        descriptor = getAssets().openFd(audio[i]);
                        mp.reset();
                        mp.setDataSource( descriptor.getFileDescriptor(), descriptor.getStartOffset(),descriptor.getLength());
                        descriptor.close();
                        mp.prepare();
                        mp.start();
                        xml();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

here the method xml() contains images and audio files that i am picking from assets folder

and also i need to play those files dynamically

please help

  • 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-29T09:28:07+00:00Added an answer on May 29, 2026 at 9:28 am

    This service load an audio file from your raw , You have to call startService() in your activity to start this service , Do not forget to add this service to your android manifest.

    EDITED

    public class Backgroundmusic extends Service {
        // Binder given to clients
        private final IBinder mBinder = new LocalBinder();
        // Random number generator
        private final Random mGenerator = new Random();
    
        private SoundPool soundPool;
        private HashMap<Integer, Integer> soundsMap;
        int SOUND1=1;
        int SOUND2=2;
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
    
        soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
        soundsMap = new HashMap<Integer, Integer>();
        soundsMap.put(SOUND1, soundPool.load(this, R.raw.baby_laugh, 1));
        soundsMap.put(SOUND2, soundPool.load(this, R.raw.touchdown, 1));
    }
    public void playSound(int sound, float fSpeed) {
        AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
        float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float volume = streamVolumeCurrent / streamVolumeMax;
    
    
        soundPool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed);
       }
    
    
    /**
     * Class used for the client Binder.  Because we know this service always
     * runs in the same process as its clients, we don't need to deal with IPC.
     */
    public class LocalBinder extends Binder {
        LocalService getService() {
            // Return this instance of LocalService so clients can call public methods
            return LocalService.this;
        }
    }
    
    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }
    
    /** method for clients */
    public int getRandomNumber() {
      return mGenerator.nextInt(100);
    }
    
    public void soundPlay(int index){
    
         playSound(index, 1.0f);
         Log.d("SOUND1","hi1");
    
    }   }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to display images and play corresponding audio files one after the other.
I'm using this code from Microsoft to play audio notifications for my application. It's
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
I want to play Audio in flex application.I am using SWFLoader for it.Is there
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I just developed an iPhone audio streaming application...Now it can play audio files without
I am using media player to play audio and video. I am creating own
I'm working on an application that will read in file paths and play audio
I want use html5's new tag to play a wav file (currently only supported
I use the following code to record audio files and play. I have a

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.