How to store an audio file into database using Android Sqlite?
I am New to 开发者_运维百科Android. My Requirement is to storing an audio file into database using Android Sqlite. can any one suggest me?
Thanks in advance.
You could use a Blob. See here an example for an image. It will be very similar to do the same with an audio file.
You could store a Blob but I would advise to store the music file in the private application directory and store the path to the file in the database.
The main reason for storing sound files on database might be product line approach. You can develop many many similar applications by just modifying your database and not touching your code.
I do not comment on application size because there are comments about it and I do not look at it.
Yes. You can store your small sized sound files in sqlite database as blob fields. It works well. First store your data in database then retrieve it and put it in a temp file. That way you can store your sound files in database.
Check this:
soundDataFile = File.createTempFile( "sound", "sound" );
FileOutputStream fos = new FileOutputStream( soundDataFile );
fos.write( soundData );
fos.close();
mediaPlayer.reset();
mediaPlayer.setDataSource( soundDataFile.getAbsolutePath() );
mediaPlayer.prepare();
mediaPlayer.start();
精彩评论