使用的Soundpool例如播放声音 [英] play sound using soundpool example
问题描述
我非常初学者到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
有深入的了解检查此<一个href="http://www.techrepublic.com/blog/app-builder/getting-your-feet-wet-in-androids-soundpool/877">Tutorial 1 和<一href="http://www.edumobile.org/android/android-programming-tutorials/sound-pool-example-in-android-development/">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.
这篇关于使用的Soundpool例如播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!