设为首页 加入收藏

TOP

Android 实现多个Audio文件的顺序播放(二)
2014-11-24 07:23:55 来源: 作者: 【 】 浏览:1
Tags:Android 实现 多个 Audio 文件 顺序 播放
he map
*/
public void playLoopedSound(String key) {


int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/ mAudioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

int soundId = mSoundPool.play(
mSoundPoolMap.get(key), streamVolume,
streamVolume, 1, -1, rate);


mKillSoundQueue.add(soundId);
// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if (!mKillSoundQueue.isEmpty()) {
mSoundPool.stop(mKillSoundQueue
.firstElement());
}
}
}, delay);
}

/**
* play the sounds have loaded in SoundPool
* @param keys the files key stored in the map
* @throws InterruptedException
*/
public void playMutilSounds(String keys[])
throws InterruptedException {
int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/ mAudioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
for (String key : keys) {
Log.d("playMutilSounds", key);
if (mSoundPoolMap.containsKey(key)) {
int soundId = mSoundPool.play(
mSoundPoolMap.get(key),
streamVolume, streamVolume, 1, 0,
rate);
//sleep for a while for SoundPool play
Thread.sleep(seperateTime);
mKillSoundQueue.add(soundId);
}


}


// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if (!mKillSoundQueue.isEmpty()) {
mSoundPool.stop(mKillSoundQueue
.firstElement());
}
}
}, delay);


}


/**
* Loads the various sound assets
* @param locale the load to load audio files
*/


public void loadSounds(String locale)
throws SAXException, IOException,
ParserConfigurationException {
Log.d("load locale", locale);
this.locale = locale;
AssetFileDescriptor afd;
Map audioFiles = util
.getAudioFileConfig(locale,
mContext.getAssets());


for (String key : audioFiles.keySet()) {
afd = mContext.getAssets().openFd(
audioFiles.get(key));
addSound(key, afd);
}


}


/**
* Stop a Sound
*
* @param index - index of the sound to be stopped
*/
public void stopSound(int index) {
mSoundPool.stop(mSoundPoolMap.get(index));
}


/**
* Deallocates the resources and Instance of SoundManager
*/
public void cleanup() {
mSoundPool.release();
mSoundPool = null;
mSoundPoolMap.clear();
mAudioManager.unloadSoundEffects();
_instance = null;


}


/**
* unload all resource in the sound pool
* support for user change VoiceLanguage or Locale or user close th

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Ubuntu 64 bit 编译 Android 下一篇Java分批读取文件

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)