Convert Byte array to 3gp file and play – Android

Get stored byte array from sqlite database

byte[] soundBytes=db.getSound(); 
// db.getSound() returns byte array from database


String outputFile=Environment.getExternalStorageDirectory().getAbsolutePath() + "/output.3gp";
File path = new File(outputFile);
FileOutputStream fos = null;
try {
     fos = new FileOutputStream(path);
     fos.write(soundBytes);
     fos.close();
} catch (Exception e) {
     e.printStackTrace();
}
MediaPlayer mediaPlayer = new MediaPlayer();

try {
     mediaPlayer.setDataSource(outputFile);
     mediaPlayer.prepare();
     mediaPlayer.start();
} catch (IOException e) {
     e.printStackTrace();
}

Leave a Reply

Your email address will not be published. Required fields are marked *