Вы можете конвертировать mp3 в bytearray следующим образом:
fun convert(context: Context): ByteArray {
val outputFile = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).absolutePath + "/sample.mp3"
var soundBytes = ByteArray(0)
try {
val inputStream = context.contentResolver.openInputStream(Uri.fromFile(File(outputFile)))
soundBytes = IOUtils.toByteArray(inputStream)
} catch (e: Exception) {
e.printStackTrace()
}
return soundBytes
}
Java
public byte[] convert(Context context) {
String outputFile =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/sample.mp3";
byte[] soundBytes = new byte[0];
try {
InputStream inputStream =
context.getContentResolver().openInputStream(Uri.fromFile(new File(outputFile)));
soundBytes = new byte[inputStream.available()];
soundBytes = IOUtils.toByteArray(inputStream);
} catch (Exception e) {
e.printStackTrace();
}
return soundBytes;
}