0

Can anyone give me a link of function to play audio file using user define time.. I am using handler but something is missing.. I am also done infinite time audio play but we need user defined times audio play.. Thanks...

Infinite time play audio is done using below function..

@Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();


          mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.shri_krushna_fast);
             // mMediaPlayer.setVolume(0.2f, 0.2f);

          mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
                  public void onCompletion(MediaPlayer arg0) {
                      mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.shri_krushna_fast);
                      mMediaPlayer.start();
                  }
              });
              mMediaPlayer.setLooping(true);
              mMediaPlayer.start();


    }

I just wanted how to play audio x times in android using Thread??

I am updating my function but i was not got 100% on this..so plz help

my updated function is as bellow

public void Repeat_mantra()
    {
         mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.shri_krushna_fast);
         // mMediaPlayer.setVolume(0.2f, 0.2f);

      mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
              public void onCompletion(MediaPlayer arg0) {

                  mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.shri_krushna_fast);
                  for(count=1;count<5;count++)
                  {
                      mMediaPlayer.start();
                      while(mMediaPlayer.isPlaying());
                  }
              }
          });    
        //  mMediaPlayer.setLooping(true);
          mMediaPlayer.start();
    }

But this function is running then other clicks/or user interface are not appear because of "while(mMediaPlayer.isPlaying());" so any help me for how to update my function with Thread??

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Amit
  • 51
  • 9
  • You should post your source, because otherwise it will be very hard to help you. Have you considered a service which is triggered by a timestamp and plays the sound? – Lama Mar 07 '14 at 11:50
  • You don't want the for or while loops; rather you need to be event based. Initialize your count before starting the first time, then decrement it in the completion listener and either start it again or not, before promptly returning from the completion listener method. – Chris Stratton Mar 08 '14 at 19:33

0 Answers0