Way to access music database with mobile app

0 votes
asked Sep 12, 2017 by brokencode

this is not a specific programming language question, instead it's more focused on the way to achieve this:

A music quiz where I have a songs database (which I can update constantly) that will play random songs and the user can answer.

My thoughts were: where I have to put this music? I mean, even if I sample 30 sec for song at 16 bit and 8000 Hz in mp3 128KB/s format, the resulting file will be around 235KB (the smallest size I can reach - I tried with 64 KB/s and the file it's 234KB and I can't figure out why - 30 * 64 = 1.920 and yes, the file was MONO). If I have 1000 songs, the database will be approssimately 235MB big, and waaaaay too heavy.

So, what I can do? My app will occupy 235MB? I let the app connect to a server and everytime it downloads all the songs? There is another way to achieve this? (I've seen many answers referring to acces the phone library, I don't want this. I want to choose the songs and deleting/updating it by myself)

3 Answers

0 votes
answered Sep 12, 2017 by napolean

I can't say about the audio creation and sampling part. Let's assume you have that 235 MB of data. In that case you can have it as part of your app with no need to download from server everytime.

You will just need to upload these files(as compressed file with .obb ext) along with your apk.

And when apk is downloaded from the playstore, the expansion files will also be downloaded within the directory Android/obb/app-package/your.obb

Here your.obb is the final file containing all the audio files. You can access each of the audio file and use it in your app.

For more information about it check the following https://developer.android.com/google/play/expansion-files.html

0 votes
answered Sep 12, 2017 by ben

Not the most secure way, but you can setup a simple LAMP server and hosts all the music files there along with a simple MYSQL database that contains a list of all the songs and their URL. Also write a PHP file that can query the database. When you start the quiz, you download the most current list of the songs by using the PHP script and it reposes with a JSON file. You can easily parse the JSON file and then insert them into a Map or the SQLite DB . Then you can just download the songs through HTTP on demand.

+1 vote
answered Sep 12, 2017 by brad

even if I sample 30 sec for song at 16 bit and 8000 Hz in mp3 128KB/s format

Those are some incredibly wonky encoding settings.

8 kHz sample rate is only appropriate for the lowest quality of voice, giving you at best a frequency response up to 4 kHz. This is music you're talking about, that sort of quality is generally unacceptable. To capture at 16-bit with 8 kHz is a waste... you'd be better off recording at 44.1 kHz in 8-bit. (Note that the bits per sample on the capture doesn't technically carry over to the MP3 encoded version so it may not matter anyway... but I'm pointing this out to you anyway so you understand why it matters in general use.)

Finally, 128 kbit/s for such a low quality capture is absurd. 128 kbit/s is a typical bitrate for 44.1 kHz/48 kHz stereo medium quality music in MP3.

the resulting file will be around 235KB

That's not all that big. Consider that the raw form is typically 8x-10x larger.

I tried with 64 KB/s and the file it's 234KB and I can't figure out why - 30 * 64 = 1.920

Encoding bitrates are typically expressed in bits not bytes, so you're missing a division by 8 there if you want bytes. When writing your bitrate, it's not 64 KB/s, it's 64 Kbit/s or 64 Kb/s. Note the little "b".

(30 seconds * 64 kilobit) / 8 bits per byte = 240 kilobytes

So, what I can do? My app will occupy 235MB?

Depends on your requirements. Does the app require a local offline copy of the entire database of music at all times? If so, you need a copy of it locally. It could be downloaded after your app is installed. I have a hunch though that you don't actually need a local offline copy of everything, because...

I want to choose the songs and deleting/updating it by myself

For this to happen (short of updating your app all the time), you'll need to distribute these files via a server somehow anyway. The easiest way to do this is via a static server. You don't need a full LAMP installation or anything like that. Just create a JSON file (or similar), dump it on some static hosting along with your media files.

The easiest way to get started is to use something like AWS S3. For that, just create a bucket, drag your files in, and now it's accessible over the internet. When you want to update stuff, just drop in your new index JSON file and new media files. Have your app download this index, and the media files as needed. Cache the media files locally if it makes sense to do so, but you can limit the cache size.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...