用的Soundpool在Android上无缝循环?Soundpool、Android

2023-09-05 11:17:53 作者:@那个远方什么摸样

我想回路短(20KB),无缝OGG文件用的Soundpool类并不能得到一致的结果,而测试硬件。它总是播放使用模拟器完美,但在我测试的一台Nexus 1,或在SAMSUMG的Galaxy Tab 10.1也有在每个循环点发声持久性有机污染物或点击。什么是很奇怪的是,虽然一旦应用程序一致已经启动,点击略有不同,每次我重新启动应用程序,并在极少数情况下(更频繁地在片)的循环正常播放。

I am trying to loop short (20kb), gapless ogg files with the SoundPool class and cannot get consistent results while testing on hardware. It always plays back perfectly using the emulator but when I test on a Nexus 1, or on a Samsumg Galaxy Tab 10.1 there are audible pops or clicks at every loop point. What is very strange is that while consistent once the application has started, the clicks are slightly different every time I restart the app and on rare occasions (more frequently on the tablet) the loop plays correctly.

结果没有更好的使用MediaPlayer的。它是不合理的期望在Android音频循环的无缝播放?当然,有人也有类似的功能是否正常?如果是的话我希望能看到它是如何工作的一个例子。

The results are no better using MediaPlayer. Is it unreasonable to expect gapless playback of audio loops on android? Surely someone has similar functionality working properly? If so I would love to see an example of how it works.

谢谢!

推荐答案

我用了一个黑客工具,工作正常,单个文件:

I used a hack that works fine for single files:

HACK_loopTimer = new Timer();
HACK_loopTask = new TimerTask() {               
    @Override public void run() {
        mMediaPlayer.seekTo(0);
    }
};
long waitingTime = mMediaPlayer.getDuration()-mHackLoopingPreview;
HACK_loopTimer.schedule(HACK_loopTask, waitingTime, waitingTime);

刚刚成立 mHackLooping preVIEW 来合理数额;我使用的是100毫秒,这是工作的罚款。我不得不承认,这是一个不太理想和丑的解决方案,但至少它的工作。

Just set mHackLoopingPreview to a reasonable amount; I'm using 100ms and it is working fine. I have to agree that this is a less than ideal and ugly solution, but at least it does its job.