android 播放wav代码,播放简短的.wav文件 - Android

Raghav Sood..

27

该的Soundpool是这个正确的类.以下代码是如何使用它的示例.它也是我在我的几个应用程序中用来管理声音的代码.您可以根据自己的喜好(或内存允许)发出声音.

public class SoundPoolPlayer {

private SoundPool mShortPlayer= null;

private HashMap mSounds = new HashMap();

public SoundPoolPlayer(Context pContext)

{

// setup Soundpool

this.mShortPlayer = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

mSounds.put(R.raw., this.mShortPlayer.load(pContext, R.raw., 1));

mSounds.put(R.raw., this.mShortPlayer.load(pContext, R.raw., 1));

}

public void playShortResource(int piResource) {

int iSoundId = (Integer) mSounds.get(piResource);

this.mShortPlayer.play(iSoundId, 0.99f, 0.99f, 0, 0, 1);

}

// Cleanup

public void release() {

// Cleanup

this.mShortPlayer.release();

this.mShortPlayer = null;

}

}

你可以通过调用:

SoundPoolPlayer sound = new SoundPoolPlayer(this);

在你的Activity的onCreate()中(或之后的任何时间).之后,播放声音简单的通话:

sound.playShortResource(R.raw.);

最后,一旦你完成了声音,请致电:

sound.release();

释放资源.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值