The best way to get song from remote database - android

I was wondering what is the best way to play song without having connection network ?
Explanation :
I have an application that play some songs. I can play a song whenever I want, even if I m in a tunnel or in a place where I dont have a network connection.
What is the best way to manage it ?
Does sqlite sufficient to save a song to a binary format ?
Should I store the music in a directory and register the sound path ?
Thanks for advance

You can store song meta-data in SQLite (like: song list, titles, authors...) but storing actual audio data in it is a bad idea. The overhead of storing BLOBs in a database is pretty big. And there is no way to play audio directly off database, so I would have to unload it all to memory or create temporary file.
I suggest you to relay on normal files located on external storage.

Related

Can end user access /storage/emulated/ and edit the data?

I want to move some media files from "/vendor/etc/" to "/storage/emulated/"
These media files are some local files used for local playback demo purposes. I donot want the end user to manipulate this data.
Can "/storage/emulated" be manipulated?
If yes, where are local media filed should be transferred to from "/vendor/etc" ?

Store mp3 files in a database?

I am currently creating a mobile android app in Android Studio for my church.
My app is basically a Bible which verses are linked to mp3 audio explanations from my preacher; however, I don't know whether I should save these mp3 files stored locally in the phone of the user or store them in a database.
I have been reading some things about databases and found out that SQLite is good, but stores the database locally, which is not what I want.
How can I solve this problem?
Every verse in the Bible is linked to a specific mp3 audio sermon/explanation from my preacher.
Relational Databases aren't necessarily meant to store actual files. Sure, you could store BLOB binary types, but I wouldn't suggest it. That's what file servers are for. For example, Amazon S3, or Firebase Storage.
You can store the URL to a file in the database, but store the actual file on a remote system to keep your applications size small.
You can cache the resources on disk lazily as the user reads said passage, or set up a system to stream them. That'd require more effort than just downloading the whole file once per device, though
I could not understand a lot from you question as there are too few details. If I understood correctly the question, the best way to implement this is to upload the mp3 you want to the server and in the android app play the file from the server (make a request to the web). In this case you will save to the database only the name of your mp3 and the link from the server to this file.
Another approach would be to convert your mp3 to base64 and save it in SQLite as a text datatype (as base64 string may have more than 256 chars long) and when needed you can decode it but it will be much slower than hosting everything to cloud
try {
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://xty/MRESC/images/test/xy.mp3");
player.prepare();
player.start();
} catch (Exception e) {
// TODO: handle exception
}

Copying a local Database and mailing it.

I have made an application which is about pets, at first I had kept the database local to the phone, however as new features arrive I want to make it a network based application with remote database. However I have around 500 downloads on the play store and I dont want my previous users to lose data. I came up with an idea of rolling out an update in which I copy all the databases to the SD card and then mail them back to me and update them in the remote database. I wonder if there is a better way to go around this. Help will be highly appreciated.
A better way would be to write a webservice to which you can send the database row by row. The webservice will then update your Server database(s).
This not only prevents duplication of your database between internal and external memory, but it also allows automation and more flexibility in the update process. You can also pause the transfer, and pick up from whichever row was last sent easily.

Android saving user's choices as favorites

I am developing a music app wherein a user can select choices of songs to play. One feature I want to implement is to save a song as favorite. Once favorite is clicked upon, it should save the user's choice and display it next time when the user logs in. None of the data is stored on the app. Everything is fetched from a server. What I intend to store is just the names of the songs. I read the Android Documentation http://developer.android.com/guide/topics/data/data-storage.html for various storage options and those which seem applicable to my case are:
Internal Storage
Database SQLLite connections
as these will store the data private to the application.
Which among these should I use? Are there any other suggestions?
How did you populate the song list? Did you have any cache or you just fetch it from the server every time? To improve the performance and be able to use your application when there is no internet connection - at least can view the song you have ,I suggest you have to provide some sort of cache. Once you have the cache, SQLite is the way to go, for both song data and favorite data.
Both of them works fine. But since your data will be a single text, i would recommend Shared Preferences, which keeps the data as in XML format and it's easy to use.

How store the data in android device securely?

I have the problem to store the downloaded data in my android device Now I store the data on my sdcard, but this is not much prevent from the user. I need to store the data securely from the user. How can I do that?
there is no way you can prevent the user from accessing your data. The max you can do is :
Make the folders you create as hidden ( prefix the folder names with a . )
remove the extension of the files you create, if possible. In most cases you can still access them & your files dont show up in other apps (like music players, Image viewers).
For storing senstive data or some downloaded dat in the application , just use internal Storage. ie "data/data/{App package name}/{direcdtory name}". if you store data inside the internal storage, only your application can access the data not the user nor other application.

Categories

Resources