Android 应用程序上循环声音的问题

发布于 2024-12-06 03:33:36 字数 488 浏览 0 评论 0原文

我遇到了一些问题。我正在尝试在我的 Android 应用程序中连续循环播放声音。

使用媒体播放器: MP3 播放正常,但末尾有一个文件中不存在的间隙。我读到它与解码器有关,并且 ogg 应该可以工作。 尝试使用ogg,但仍然得到间隙,这绝对不在文件中。

使用 SoundPool 类和 ogg(使用这个家伙有趣的类:http ://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html),

声音开始,几分之一秒后,它重新启动。所以我在每个文件的开头都会有半秒的卡顿,没有 进一步前进,因为总是要回到起点。

媒体播放器及其循环音频的能力真的有问题吗?奇怪的口吃音池怎么样?

非常感谢您的帮助!

A bit of a problem has presented itself to me. I am trying to play a sound continously looping in my android app.

With MediaPlayer:
MP3 plays alright, but there is a gap at the end which does not exist in the file. I read it had to do with the decoder, and that ogg should work.
Tried using ogg, but still get the gap, which is definitely not on the file.

With SoundPool classes and ogg (using this fellow's interesting class: http://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html),

the sound starts, and a fraction of a second later, it restarts. so I get a stutering half a second of the beginning of every file, without
advancing further, because it is always going back to the beginning.

Is there something really wrong with media player and it's ability to loop audio? How about the freakishy stuttering soundpool?

Thank you very much for any assistance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-12-13 03:33:36

我使用以下代码来循环声音(其中声音扩展名为 .ogg),而不是使用声音池,让我们尝试使用媒体播放器,这是我用来循环音频的代码,它对我来说效果很好,让我们尝试一下,

MediaPlayer mediaPlayer;


setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();

try {
            AssetManager assetManager = getAssets();
            AssetFileDescriptor descriptor = assetManager.openFd("music.ogg");
            mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
                    descriptor.getStartOffset(), descriptor.getLength());
            mediaPlayer.prepare();
            mediaPlayer.setLooping(true);
        } catch (IOException e) {
            textView.setText("Couldn't load music file, " + e.getMessage());
            mediaPlayer = null;
        }

I use the following code to looping soung (where sound with extension .ogg), instead of using sound pool lets try with Media player,This is the code i used to looping audio its work fine for me lets have a try,

MediaPlayer mediaPlayer;


setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();

try {
            AssetManager assetManager = getAssets();
            AssetFileDescriptor descriptor = assetManager.openFd("music.ogg");
            mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
                    descriptor.getStartOffset(), descriptor.getLength());
            mediaPlayer.prepare();
            mediaPlayer.setLooping(true);
        } catch (IOException e) {
            textView.setText("Couldn't load music file, " + e.getMessage());
            mediaPlayer = null;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文