【问题标题】:libgdx music compatibilitylibgdx 音乐兼容性
【发布时间】:2018-12-29 18:24:46
【问题描述】:

是否有使用 libgdx 的音乐的兼容性列表?我在使用某些文件扩展名(例如 flac 和 wav)时遇到了一些困难。 libgdx 似乎不支持 Flac,而 wav 文件似乎仅限于 16 位采样。尝试播放 flac 音乐时收到错误消息:

未知的音乐文件扩展名:aFlacFile.flac

错误追溯到libgdx newMusic方法:

public OpenALMusic newMusic (FileHandle file) {
    if (file == null) throw new IllegalArgumentException("file cannot be null.");
    Class<? extends OpenALMusic> musicClass = extensionToMusicClass.get(file.extension().toLowerCase());
    if (musicClass == null) throw new GdxRuntimeException("Unknown file extension for music: " + file);
    try {
        return musicClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);
    } catch (Exception ex) {
        throw new GdxRuntimeException("Error creating music " + musicClass.getName() + " for file: " + file, ex);
    }
}

正如错误所述,*.flac 似乎不是受支持的扩展。我尝试播放的 flac 文件的位深度为 16 位,位速率为 588kps,采样率为 44 kHz。此外,一些 wav 文件可以工作,而另一些则不能:

创建音乐时出错 com.badlogic.gdx.backends.lwjgl.audio.Wav$Music 对于文件:aWavFile.wav

...

GdxRuntimeException:读取 WAV 文件时出错:aWavFile.wav

...

GdxRuntimeException:WAV 文件每个样本必须有 16 位:24

其他人似乎也遇到过这个问题:Android Java LibGDX Music, Sound,正如解决方案评论和我抛出的异常中所述,wav 采样需要 16 位的速率。 Android 开发者网站https://developer.android.com/guide/topics/media/media-formats 指出应该支持 flac,而 wav 仅限于 8/16 位线性 pcm。 Gamefromscratch https://youtu.be/GN2KV4zQfEk?t=1712 的 Youtube 教程提到,由于多平台兼容性,libgdx 音频的灵活性可能低于标准实用程序。 猜猜我的问题又回到了:libgdx 是否有音乐扩展的兼容性列表?

【问题讨论】:

    标签: libgdx playback


    【解决方案1】:

    我尝试了以下格式:

    1. mp3
    2. ogg
    3. Wav(16 bit)
    

    当您尝试加载时,其他格式可能会导致问题。

    【讨论】:

    • iOS 是否支持 ogg?
    • 没有@MrStahlfelge。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-15
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多