本文介绍了Android版的Soundpool时机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在的Soundpool声音prevent截断可靠的方法?我有一些成功与声音之间的睡眠()函数,但他们仍然有时很想念声音的最后一位开始另一种声音之前。我的应用程序起着短的声音序列。
杰里

Is there a reliable way to prevent truncating of sounds in soundpool? I have had some success with the sleep() function between sounds, but they still sometimes miss the last bit of sound before starting another sound. My app plays short sounds in sequence.Jerry

推荐答案

尽管这是一个老问题,我想我会在这里发布的东西,因为我无法找到一个解决这个问题的在线,但没有拿出什么一个解决方案...

Although this is an old question, I thought I would post something here since I couldn't find a solution to this problem online but did come up with something of a solution...

我得到的每一个声音的持续时间(使用的MediaPlayer)时,我的应用程序启动,并存储R.id.sound_name值和持续时间在一起。然后我就可以使用的Soundpool播放声音。

I get the duration of each sound (using MediaPlayer) when my app starts up, and store the R.id.sound_name value and the duration together. I can then play the sounds using the SoundPool.

code来获得持续的时间:

Code to get duration:

private long getSoundDuration(int rawId){
  MediaPlayer player = MediaPlayer.create(context, rawId);
  int duration = player.getDuration();
  return duration;
}

在我的声音课,我再播放声音和往常一样那么持续时间睡觉。 pretty简单的东西。

In my sound class, I then play the sound as usual then sleep for the duration. Pretty simple stuff.

似乎运作良好。让我从的Soundpool低延迟,再加上能力的优势,以连锁的东西。

Seems to work well. Gives me the advantages of low-latency from SoundPool, plus ability to chain things.

一对夫妇的注意事项:


  • 每次不要持续时间,与创建的MediaPlayer有开销。

  • 持续时间是从文件的元数据所 - OGG格式的工作非常适合我,但我不能保证别的

这篇关于Android版的Soundpool时机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:01