我有一个问题,如何将我的音频文件发送到我的服务器,我曾尝试转换为 base64,但没有任何效果。这是我的代码
变量声明:
private MediaRecorder grabacion;
private String archivoSalida = null;
通过媒体记录获得的音频:
archivoSalida = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Myrecord.mp3";
grabacion = new MediaRecorder();
grabacion.setAudioSource(MediaRecorder.AudioSource.MIC);
grabacion.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
grabacion.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
grabacion.setOutputFile(archivoSalida);
转成base64,这里报错:
private String convertirAudString(MediaRecorder audio){
ByteArrayOutputStream array=new ByteArrayOutputStream();
byte[] audioByte = new byte[(int)audio.length()];//error in this line
String audioString = Base64.encodeToString(audioByte,Base64.DEFAULT);
return audioString;
}
最佳答案
感谢您的所有建议。
我解决了这个问题,使用
文件 file = new File(Environment.getExternalStorageDirectory() + "/Miaudio.mp3");
byte[] bytes = new byte[0];
bytes = FileUtils.readFileToByteArray(文件);
然后我将它转换成base64;它非常适合我。
关于android - Android音频文件编码base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58172320/