如何在gdx中播放声音? [英] How to play sound in gdx ?

查看:104
本文介绍了如何在gdx中播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨每一个



我有背景音乐,我想在游戏开始时播放音乐,但音乐没有播放我没有知道为什么任何人都可以帮我解决这个问题



看到代码

Hi every one

I have background music, and I want to play the music when the game start, but the music didn't play I don't know why can any one help me to solve this problem

see the code

 public void create() {
.
.
.
.
backgroundMusic =  Gdx.audio.newSound(Gdx.files.internal("musicBG.mp3"));
backgroundMusic.play(0.5f);
}





我的尝试:



我试过这个流媒体音乐·libgdx / libgdx Wiki·GitHub [ ^ ]

推荐答案

根据我对LibGDX的理解,如果您使用的音乐文件太大,音乐将无法使用Sound类播放。 Sound类的含义正是它所说的,声音和简短的。



我的解决方案:

当我编码时使用LibGDX的游戏我总是使用音乐类:



私人音乐背景音乐;

backgroundMusic = Gdx.audio.newMusic(Gdx.files。内部(musicBG.mp3));



希望这会有所帮助!



如果没有,我建议在不同的音乐文件类型之间进行试验,例如.wav
From what I understand of LibGDX, music will not play using the Sound class if the music file you are using is too large. The Sound class was meant for exactly what it says, sounds, and short ones at that.

My Solution:
When I am coding games using LibGDX I always use the Music class:

private Music backgroundMusic;
backgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("musicBG.mp3"));

Hope this helps!

If it does not, I would suggest experimenting between different music file types such as .wav


这篇关于如何在gdx中播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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