Question about music handing ?

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Question about music handing ?

Postby rosabella » Fri Jul 13, 2018 7:34 am

Hello everyone,

I want to set a different music for each levels of my game.
Do I need whene the level is completed to Dispose muiscLevel01 and then if the user choose to go to level02 to load musicLevel02 etc...

Actually for testing I did a Musics class manager because I first wanted to load all Musics like I do with graphics.
CODE: SELECT ALL
public class Musics {
public static AssetManager musicManager = new AssetManager();

public static Music musicLevel01;

public Musics() {

}

public static void loadMusic(String file) {
musicManager.load(file, Music.class);
}

public static Music getMusic(String file) {
return musicManager.get(file, Music.class);
}

//Here for all musics i will need
public static void loadMusics() {
loadMusic("music/IncredFx - Theme remix.mp3");
}

//Here for all musics i will need
public static void getMusics() {
musicLevel01 = getMusic("music/IncredFx - Theme remix.mp3");

}

public static void playLoopMusic(Music m) {
if (!m.isPlaying()) {
m.setVolume(0.5f);
m.setLooping(true);
m.play();
}
}

[.....]
}


So what I actually did is accessing the music needed and playing it at the corresponding level.
The musicDispose method is called in the dispose() method of GameScreen class

Can anybody help me on the best way to handle this and do not have memory problem with old mobile devices, ?
rosabella
 
Posts: 1
Joined: Fri Jul 13, 2018 7:10 am

Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest