I want load mp3 song in an android app with libgdx library but i don't find the way to works. I don't know how programm this "issue".
Assets Manager could be the class for works with mp3 song?
I found also this way:
Gdx.files.newMusic(file);
but in Android don´t work and desktop the same code work.
Update: Parse Method
public void parse() {
JsonReader reader = new JsonReader();
JsonValue rootElem = reader.parse(file);
JsonValue songDataElem = rootElem.get("songData");
JsonValue notesDataElem = songDataElem.get("notes");
JsonValue barsDataElem = songDataElem.get("bars");
JsonValue keysDataElem = songDataElem.get("keys");
JsonValue audioDataElem = rootElem.get("audioData");
NoteData[] notes = new NoteData[notesDataElem.size];
for (int i = 0; i < notesDataElem.size; i++) {
notes[i] = new NoteData(notesDataElem.get(i).getInt("pitch"), notesDataElem.get(i).getFloat("time"));
}
BarData[] bars = new BarData[barsDataElem.size];
for (int i = 0; i < barsDataElem.size; i++) {
BarData bar = new BarData(barsDataElem.get(i).getFloat("time"));
bars[i] = bar;
}
char[] keys = new char[keysDataElem.size];
for (int i = 0; i < keysDataElem.size; i++) {
keys[i] = keysDataElem.getChar(i);
}
float tempo = songDataElem.getFloat("tempo");
String file = audioDataElem.getString("file");
songData = new SongData(notes, bars, keys, tempo);
parsed = true;
}
and the constructor:
public SongFile(FileHandle file) {
manager = new AssetManager(new ExternalFileHandleResolver());
file = Gdx.files.external(file.path());//30
if (file.exists()) {
manager.load(file.path(), Music.class);
manager.finishLoading();
music = manager.get(file.path(), Music.class);
music.setLooping(true);
music.play();
}
}
In the main class:
String file = "/storage/emulated/0/download/prueba.mp3";
SongFile songFile = new SongFile(new FileHandle(file));
songFile.parse();
song = songFile.makeSong();