Libgdx:声音循环中的滞后 [英] Libgdx: Lags in soundtrack looping

查看:180
本文介绍了Libgdx:声音循环中的滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在libgdx中遇到音乐循环问题。我知道之前有一个simmilair主题,但它根本没有帮助我。问题是当你进入我的游戏主菜单时(链接)下雨的声音循环。不幸的是,每场比赛之间都有一段短暂的沉默,我不知道为什么 - 你可以下载游戏,看看我的意思。我已经在使用.ogg格式,所以我在这里找到的另一个主题的解决方案并没有真正帮助。

I'm having trouble with music looping in libgdx. I know a simmilair topic was here before, but it didn't help me at all. The thing is that when you go to main menu in my game (link) the sound of rain is looped. Unfortunately, there is a short moment of silence between each play and I don't know why - you can download the game and see what I mean. I'm already using .ogg format, so the solution from the other topic I found here didn't really help.

如果我在Audacity的循环中播放这个声音,它的效果非常好。

If I play this sound in a loop in Audacity, it works perfectly.

这是我的代码(我认为它不会有所帮助):

Here is my code (I don't think it'll help, though):

rainSoundtrack = Gdx.audio.newMusic(Gdx.files.internal("soundtrack.ogg"));
rainSoundtrack.setLooping(true);


推荐答案

问题在于libGDX处理音乐的方式。我将在 GitHub issue 1654 上引用一篇badlogic帖子。

The problem is the way libGDX handles Music. I will quote a badlogic post on GitHub issue 1654.


Android情况有点复杂和悲伤。在Android上,我们使用系统工具来播放音频,即MediaPlayer。这些Android软件使用引擎盖下的设备依赖驱动程序(音频驱动程序,自定义编解码器实现等)。这意味着我们受三星等硬件供应商及其驱动程序实施的支配。

the Android situation is a bit more complicated and sad. On Android we use the system facilities to playback audio, namely MediaPlayer. This pieces of Android software uses device dependend drivers under the hood (audio drivers, custom codec implementations, etc.). This means that we are at the mercy of hardware vendors like Samsung and their driver implementations.

问题不仅限于libGDX,它是 Android issue 18756

The problem is not bound only to libGDX, it is Android issue 18756.

解决方案

您的音轨在内存大小方面很短且很小,所以使用libGDX声音实际上更好这种情况,它没有这个差距错误。

Your soundtrack is short and small in term of memory size so using libGDX sound is actually better in this case and it is free of this gap bug.

音乐 - >长文件和大文件,没有加载到内存

Music -> long and big files, not loaded into memory

声音 - >短文件和小文件,加载到内存中

Sound -> short and small files, loaded into memory

使用Sound类并循环它。示例:

Use Sound class and loop it. Example:

long id;
...
public void create() {
    music = Gdx.audio.newSound(Gdx.files.internal("soundtrack.ogg"));
    id = music.loop(); //Sound may not be ready here!
}

public void render() {
    if(id == -1)
        id = music.loop();
}

这篇关于Libgdx:声音循环中的滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆