Vijay
Vijay

Reputation: 3502

Android - Which is best way to store the mp3 files

I am new to android. I am going to develop a simple mp3 application. There will be some mp3 tones in my app. I want to play the tones on click in the list item. Now my question is Which is the best way to store the mp3 files in my app.

1) SQLite

2) XML

3) folder

Please let me some good idea to me.

Thanks in advance.

Upvotes: 1

Views: 646

Answers (1)

Sebastian Walla
Sebastian Walla

Reputation: 1124

You have to store them in a folder. There must be any resource the sqlite entrys refer to, because this is just a database. So storing them in a folder is not a question I think...

And XML is used to define UI Things like the interface. This is because of the Model-View-Controller pattern if you want to know more about that look here

If you safed it in the raw folder(it´s located in the res folder, if you dont have one-> create one) of your project than this should be suitable for you

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start();

If you got it somewhere else this should fit your needs

Uri myUri = Uri.parse("/path/to/file.mp3"); // initialize Uri here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();

For more informations about MediaPlayer see here and here

Upvotes: 1

Related Questions