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

烂漫一生 提交于 2019-11-30 20:21:49

问题


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:


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



来源:https://stackoverflow.com/questions/9866927/how-to-play-multiple-ogg-or-mp3-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!