I'm trying to play 20 ogg files at the same time using MediaPlayer.
This is because I want to make a mixing effect.
While one music is playing, other files also have to be played.
Actually, I already made an application with this function by iOS, and it didn't have any problems to play and mix.
And now, I should convert this app into android app.
so I sentenced 20 mediaplayer variables
MediaPlayer player1;
MediaPlayer player2;
MediaPlayer player3;
.....
play1 = (Button)findViewById(R.id.btn1);
play2 = (Button)findViewById(R.id.btn2);
play3 = (Button)findViewById(R.id.btn3);
......
play1.setOnClickListener(this);
play2.setOnClickListener(this);
play3.setOnClickListener(this);
......
and whenever I click each button, it play each sound and mix.
player1 = MediaPlayer.create(TestActivity.this, R.raw.md_cricket2);
player1.setLooping(true);
player1.start();
......
However, I have some problems at this point.
Two sounds mixing is ok, but when I tried to play more than 3 sounds,
some noises like "tick, tick" are added. It sounds like white noise..
I don't know why...
I thought it is really simple to make this mixing application in android, because
I already did it in iOS, but I don't know what the problem is...
Is there anybody who can advise me?
I think soundpool is not an answer. It is only for short sounds.
MediaPlayer is not proper to play multiple sounds at the same time?
Then, How can I make this function?
Playing sounds simultaneously with multiple media players is not recommend (crashes may occur).
You'd better use soundpool. Unfortunately, I don't have any experience with it myself so I can't help you there, but perhaps this post will help
Related
All my code works fine. I can load and play all my sound.
I load 200 sound with a player array for play one of them all or more at same time.
But I have a last problem. Now when I play a sound, the quality is very bad sometimes or if I spam it, it really bad like robot.
I need to create an app like a DJ sound tab.
With a lot of sound I can spam with buttons. I'm using RythmGame Sample. But maybe my problem is I need to more custom the mixer or something like that. Can someone help me with that please ?
I've been trying to make multiple sounds work simultaneously but I kept getting errors like Sample not ready and Error creating AudioTrack. Though I've taken care of the first error, the other error persists.
I'm using two mp3 files, that are away above 5 mb(>4 minutes) and thus was wondering if SoundPool is the right way to go about it? I can use Media Manager but it doesn't let me play multiple files simultaneously.
SoundPool is recommended for <1MB sound clips, so I'd use MediaPlayer in your case. You can call the following for each sound and they will play simultaneously:
MediaPlayer.create(YourActivity.this, R.raw.your_sound).start();
Or you can create multiple MediaPlayer objects and play a sound on each, then release() them.
Currently my code plays a sound when there is contact between any objects in my game using andEngine and Box2D and the walls, the problem I have is that when contact is made with any objects it starts again I understand why this is happening. What I want to do if possible is keep playing the sound while also playing it for another collision. I think I may need to use threads but I am unsure how to do this in java for android.
#Override
public void beginContact(Contact contact)
{
Rattle.this.mExplosionSound.play();
}
UPDATE: I don't seem to have been able to fix the issue but I know that what I need to do is play this sound multiple times simultaneously, I have tried threads and the soundPool but got no luck with either still not sure what to do.
It seems you have only one instance of the sound. Then you call play on the same sound twice, therefore it stops playing and starts from the beginning.
Imagine having one CD player - you press play, the music starts to play. You press play again and the player starts reading the track from the beginning. What you need is two players, therefore you may need two instances of the same sound.
(I don't have much experience with sound on Android so I may be wrong, please take the advice with a grain of salt.)
Even I was developing a game some time back and I found a similar problem. You should use SoundPool to play short sounds like crashing and collisions. here are some good linkswhich helped me. Link 1, link 2.
I am doing a cards game for android and I want that everytime a card is thrown, to play throwing sound. It is the same file. I will have also other sounds playing like background music , and certain clicks.
What do you recommend to use, sound pool or create MediaPlayback and play it? What would be the advantage/disdvantage to each one? should I use ogg or mp3/wave file?
Any help in this is appreciated.
Thank you
I would use the sound pool for short clips. I might be wrong but the sound pool has a smaller overhead plus it's the correct way to play short clips, it also allows you to specify how many times per second said sound clip can play which helps slower phones.
With regards to the mp3 vs ogg I use mp3. I don't believe there is any performance issues. Ogg is licence free but that doesn't really matter with regards to your app. Plus it might help if you plan on using these clips on another platform that doesn't play ogg files. No names mentioned :P
Maybe anybody faced with this issue.
I use SoundPool for playing sounds in my app.
After playing the sound I need to do further action. But how can I determine that the sound has stoped?
All the sounds in the app have a different length, so I can not count the time. I need a different approach.
Thank you.
soundpool's purpose is to load and play simple small sounds without the need to monitor them.
what you probably need is MediaPlayer and setOnCompletionListener() :
http://developer.android.com/reference/android/media/MediaPlayer.html
http://developer.android.com/reference/android/media/MediaPlayer.html#setOnCompletionListener(android.media.MediaPlayer.OnCompletionListener)