How to play 2 audio files in a short time

All your problems with Audio, Video and Images.

How to play 2 audio files in a short time

Postby Dahevos » Mon Dec 20, 2010 3:54 pm

Please read the second message just under this one.
this problem in this message is already fixed.


Hi !

First of all, i'm french and i am really apologize for my very bad english.
I wanna know how to play 2 audio file (in my res/raw folder on Eclipse) in a very short time.
I try with many way :
- create 2 MediaPlayer for that : not good i think (memory, but also because i have the two sound on the same moment (so bad!!) or the two sound but too separated)
- try to use that two time :
Code: Select all
mediaPlayer.reset();
FileDescriptor fd = getResources().openRawResourceFd(sound).getFileDescriptor();
// sound is an Integer : R.raw.something
mediaPlayer.setDataSource(fd);
mediaPlayer.prepare();
mediaPlayer.start();

but doesn't work, no sound at all !!!

I wanna the sound a bit like when you speak, i mean : for "hello everybody", i wanna hello and then suddenly just after that "everbody", not at the same time of course and if it's too long is not realist so not good !

So if you have a solution, i tried to find on the internet but i found nothing intersting :|
Thanks you very much !!!
Last edited by Dahevos on Mon Dec 20, 2010 7:06 pm, edited 1 time in total.
Dahevos
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 20, 2010 3:45 pm

Top

Re: How to play 2 audio files in a short time

Postby Dahevos » Mon Dec 20, 2010 7:05 pm

Some news :

here is my main code:
Code: Select all
              mediaPlayer = new MediaPlayer();
      
              playSound(tabSigne[i].getSon1());
              while (mediaPlayer.isPlaying()) {
                 
              }      
              playSound(tabSigne[i].getSon2());
              while (mediaPlayer.isPlaying()) {
                   
              }
              mediaPlayer.release();


and my helpful procedure :

Code: Select all
   public void playSound(Integer sound) {
      
      Uri musicfile = Uri.parse("android.resource://" + getPackageName() + "/" + sound);
      mediaPlayer.reset();
      try {
         mediaPlayer.setDataSource(getApplicationContext(), musicfile);
         mediaPlayer.prepare();
         mediaPlayer.start();
      } catch (IllegalArgumentException e) {
           e.printStackTrace();
      } catch (SecurityException e) {
           e.printStackTrace();
      } catch (IllegalStateException e) {
           e.printStackTrace();
      } catch (IOException e) {
           e.printStackTrace();
      }
      
   }


But when i play the 2 sound it was like that :
*sound 1*
around 1~2sec with nothing
*sound 2*
and Me i wanna without the 1~2sec (i prefer as shorter as android can, maybe around 0.5s max)

How i can do that ?
thanks !
Dahevos
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 20, 2010 3:45 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 20 guests