gpt4 book ai didi

java - 如何将音频(3gp)文件上传到firebase存储?

转载 作者:行者123 更新时间:2023-12-01 16:36:43 26 4
gpt4 key购买 nike

EDIT: I have added in 'recRef' ".3gp" at the end of the reference and now when I use the emulator it uploads as .3gp file of 0KB and external device still uploads an "application/octet-stream" file (weight 0KB).

我对我的应用进行了记录 Activity ,但无法将其正确上传到 Firebase 存储。我尝试根据谷歌发布的图像上传示例构建一个上传过程,它上传一个空文件(0KB,类型“application/octet-stream”)。录制过程运行良好,我制作了一个播放按钮来检查它,所以我知道这只是一个问题,我不知道如何将其正确上传到云端。

欢迎大家使用我的git弹出记录 Activity :https://github.com/tidharon/Popup-Record-Window-App

这是我的上传代码:

recRef = storage.getReference(lastAct + " Records").child(lastTitle);
metadata = new StorageMetadata.Builder().setCustomMetadata(lastID, outputFile).build();


ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] daata = baos.toByteArray();
uploadTask = (UploadTask) recRef.putBytes(daata, metadata).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
recURL = recRef.toString();
getIntent().putExtra("recURL", recURL);
}
});

recRef 是一个 StorageReference 元素。元数据是 StorageMetadate 元素。lastID 是连接到记录的文本文档的 ID。outputFile是存储记录的目录

这是录制过程的准备工作:

outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + ("/" + lastAct + " | " + lastID + " | " + date + ".3gp");
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);

提前致谢!

最佳答案

使用此命令检查导致问题的原因

.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MyContext, e.toString(), Toast.LENGTH_LONG).show();
}
})

代码中的 addOnCompleteListener 关闭后

关于java - 如何将音频(3gp)文件上传到firebase存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61934354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com