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.
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()) {


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, ?
Posts: 1
Joined: Fri Jul 13, 2018 7:10 am

Re: Question about music handing ?

Postby BrinaLowe » Mon Sep 17, 2018 9:42 am

I am also curious on this topic and i had created one thread a while back but there was not even a single answer or reply from anyone about this. Hope here they address the answers i need.
Posts: 1
Joined: Mon Sep 17, 2018 9:40 am

Re: Question about music handing ?

Postby Magnesus » Mon Sep 17, 2018 1:23 pm

I always dispose of the old music before playing new one. Basically I do this every time I want to change music:

Code: Select all
music =;

This worked for me fine for years.
Posts: 1649
Joined: Sun Sep 25, 2011 3:50 pm

Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest