Click here to Skip to main content
15,663,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Java
 public void create() {
.
.
.
.
backgroundMusic =  Gdx.audio.newSound(Gdx.files.internal("musicBG.mp3"));
backgroundMusic.play(0.5f);
}


What I have tried:

I tried this Streaming music · libgdx/libgdx Wiki · GitHub[^]
Posted
Updated 17-Jul-17 15:17pm
v3

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900