Convert recorded 3gp file to Byte array and store in SQLite database – Android

Use MediaRecorder and store audio in outputFile

outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gp";;
byte[] soundBytes;

try {
    InputStream inputStream = getContentResolver().openInputStream(Uri.fromFile(new File(outputFile)));
    soundBytes = new byte[inputStream.available()];

    soundBytes = toByteArray(inputStream);
}catch(Exception e){
    e.printStackTrace();
}


public byte[] toByteArray(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int read = 0;
        byte[] buffer = new byte[1024];
        while (read != -1) {
            read = in.read(buffer);
            if (read != -1)
                out.write(buffer,0,read);
        }
        out.close();
        return out.toByteArray();
    }

Leave a Reply

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