简体   繁体   中英

Libgdx. No music on Android emulator and device. Desktop app is okay

My code is as follows:

import com.badlogic.gdx.audio.Sound;
 ...
public static Sound music;
String musicFile;
if (ANDROID) musicFile="music.mp3";
else musicFile="assets/music.mp3";
music=Gdx.audio.newSound(Gdx.files.internal(musicFile));
music.play();
music.loop();

It plays on Desktop app. But what's wrong on Emulator and smartphone? ANDROID=true for Android and false for desktop app. Thanks.

You seem to have a slight missunderstanding how assets are managed by libgdx. Please refer to http://code.google.com/p/libgdx/wiki/FileHandling and the rest of the wiki. There's no need to special case for a platform.

You should also always post stack traces for others to help pinpoint the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM