Search code examples
androidmp3android-sqliteandroid-mediaplayerandroid-resources

Using raw file when trying to make local SQLite database


Currently I'm working with a SQLite database that will pull .mp3s from the device's external memory (like an SD) that stores all the albums content (like album artwork, track name, ect.) in a MediaPlayer in my DataBase. My goal is to get it to have already preloaded .mp3s once the .apk is extracted, so I tried to store .mp3s in raw to make R.raw.song calls but I got errors because my song had capital letters and number, I want tot keep them that way, and I'm not wanting to relabel each one and I want to utilize this DataBaseHelper. How can I have preloaded content in my DataBase if I keep getting this error?

Error:Execution failed for task ':audiobook:mergeDebugResources'.
> /Users/user/Downloads/MaterialAudiobookPlayer/audiobook/src/main/res/raw/102 - Trafalgarsquare.mp3: Error: Invalid file name: must contain only lowercase letters and digits ([a-z0-9_.])

Solution

  • How can I have preloaded content in my DataBase if I keep getting this error?

    This has nothing to do with a database. It has everything to do with valid resource names, and your files do not have valid resource names.

    To package arbitrarily-named files in your app, put them in your assets/ directory and use AssetManager to access them.

    Or, if you want to keep them as raw resources for easier playback with classes like MediaPlayer, rename them to have valid filenames for resources.