我正在尝试上传音频火,但当我播放下载的URL只是挂电话时,其格式不正确
private void uploadFileToDataBase(Uri uriMain, final String type, String meta) {
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType(meta)
.build();
UserFirebase.getmStorageRef().child("Audio").child(uriMain.getLastPathSegment()).putFile(uriMain, metadata)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
while (!uri.isComplete()) ;
Uri url = uri.getResult();
sendFirebaseMessage(String.valueOf(url), type);
}
});
}
这就是我获取音频文件的方式
public void MediaRecorderReady() {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
我正在播放这样的音频
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(context, Uri.parse(firbaseUrl);
player.prepare();
player.start();