How to play multiple ogg or mp3 at the same time..

2019-02-16 01:07发布

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?

1条回答
手持菜刀,她持情操
2楼-- · 2019-02-16 01:37

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

查看更多
登录 后发表回答