0

I need to use Android's MediaPlayer class from within a libGDX application to use its setNextMediaPlayer method so that I can smoothly transition from one track to another. So I want to write a generic MusicPlayer interface that each platform would need to implement. The desktop version would just not have a smooth transition, but the Android version would. The problem is, I'd like this interface to take a FileHandle which contains the music asset, but MediaPlayer takes either a resource ID or a URL.

The only other option I can thing of is, instead of having the interface take a FileHandle, let each platform read their own files and either find a way to get a resource ID or a URL from the assets folder or put the music file in the res/raw folder. The problem with this is that I'd also need to put them in the assets folder so that the desktop version (which will be using libGDX's music player) can read it. Unless there is a way to tell libGDX to read from the desktop folder so that the music file doesn't get compiled into the apk twice.

Any idea how I can solve this?

Juan
  • 15,274
  • 23
  • 105
  • 187
  • did you ever get this working? I'm trying to do the exact same thing now myself (for the exact same reason I expect, the jump in looping audio/music) – Russ Wheeler Mar 07 '17 at 23:28

1 Answers1

0

libGDX uses assets, not resources, so the resource ID cannot be used.

The below question answers the other part:

There is no "absolute path for a file existing in the asset folder". The content of your project's assets/ folder are packaged in the APK file. Use an AssetManager object to get an InputStream on an asset.

however you can try using the following uri:

file:///android_asset/<asset_path>, where is the relative path within your project's assets/ directory.

How to get URI from an asset File?

Community
  • 1
  • 1
p.streef
  • 3,652
  • 3
  • 26
  • 50