使用的Soundpool例如播放声音声音、Soundpool

2023-09-12 09:34:43 作者:梦想理应飞翔

我非常初学者到Android编程,我想学习如何使用的Soundpool方法,我有搜索一下吧,但所有我发现似乎不容易理解!我想请你给我一个很简单的例子,运行2的声音。 我真的AP preciate你的帮助。

I am very beginner to android programing, and I would like to learn how to use soundpool method, I had search about it but all I found seems not easy to understand!I would like you to show me a very simple example that run 2 sounds. i really appreciate your help.

推荐答案

命名为1,创建1个文件夹的生 yourApp下/ RES /

1.Create 1 folder named as raw under yourApp/res/

2.Do复制并粘贴您的铃声此文件夹中

2.Do copy and paste your ringtone in this folder

有深入的了解检查此Tutorial 1 和Tutorial 2

for depth understanding check this Tutorial 1 and Tutorial 2

SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

 /** soundId for Later handling of sound pool **/
 int soundId = sp.load(context, R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone

 sp.play(soundId, 1, 1, 0, 0, 1);

 MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.windows_8_notify); // in 2nd param u have to pass your desire ringtone
 //mPlayer.prepare();
 mPlayer.start();

您还可以设置监听器

 sp.setOnLoadCompleteListener(new OnLoadCompleteListener()
 {
    @Override
    public void onLoadComplete(SoundPool soundPool, int sampleId,int status) {

 }
 });

有关棒棒糖检查@ user3833732答案。

For lollipop check @user3833732 answer.