简体   繁体   English

同时播放两首mp3歌曲

[英]Play two mp3 song at the same time

I want to play two song (mp3) at the same time (one is karaoke file and one is the record audio by user).我想同时播放两首歌曲(mp3)(一首是卡拉 OK 文件,一首是用户录制的音频)。 Can I use the MediaPlayer to do this?我可以使用 MediaPlayer 来执行此操作吗? If so, is that right if I create 2 object of MediaPlayer and setDataSource for two file and play it?如果是这样,如果我为两个文件创建 2 个 MediaPlayer 对象和 setDataSource 并播放它,那对吗?

Thanks!谢谢!

是的,根据我的说法,使用两个 MediaPlayer 对象并这样做就很好,根据我的经验,声音播放或任何内存问题都没有任何问题,就像魅力一样。

When I dropped SoundPool from my game I created about 40 MediaPlayer instances for sound effects with permanent small sources, besides a background instance where a large source would change depending on the character's game area.当我从游戏中删除 SoundPool 时,我创建了大约 40 个 MediaPlayer 实例,用于具有永久小源的音效,此外还有一个背景实例,其中大源会根据角色的游戏区域而变化。 Never had any issues with simultaneous play.同时播放从来没有任何问题。

If you're going to stop a sound mid-play, be sure to use pause() instead of stop() or the instance won't play again without re-creation (an odd implementation choice IMHO):如果您要在播放中停止声音,请务必使用 pause() 而不是 stop() 否则实例不会在没有重新创建的情况下再次播放(恕我直言,这是一个奇怪的实现选择):

campfire_mp.pause();
campfire_mp.seekTo(0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM