I store my audio file in a sqlite database (like a BLOB), and now I want to get it from db, and also play it when I click the button. my db table has three fields: rowID, image, audio so that in each row of my table the image and sound are saved (like a BLOB).
I tried this but did not work for me:
byte[] byteAudio2 = null; Cursor cur1 = db.query("audiofromdb_tbl", null, null, null, null, null, null); cur1.moveToFirst(); byteAudio2 = cur1.getBlob(cur1.getColumnIndex("audio")); File tempWav = null; FileOutputStream fos = new FileOutputStream(tempWav); fos.write(byteAudio2); fos.close(); MediaPlayer mp = new MediaPlayer(); mp.setDataSource(fos.getFD()); mp.prepare(); mp.start();
source share