我在android中做了一个简单的应用程序进行练习。它应该做的是:
正在录制音频。但是,当我提供停止按钮时,它不会将其上传到Firebase存储中。它没有显示任何错误。
您能告诉我这段代码有什么问题吗。
pathsave = Environment.getExternalStorageDirectory().getAbsolutePath()+"/" +
UUID.randomUUID().toString()+"_audio_record.3gp";
.
.
.
void uploadFile(){
StorageReference riversRef = mStorageRef.child("audio/record.3gp");
riversRef.putFile(Uri.parse(pathsave))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
//Uri downloadUrl = taskSnapshot.getDownloadUrl();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
}
});
}
我想我已经添加了必要的依赖项
build.gradle(app)
apply plugin: 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-storage:19.1.1'
google-services.json文件
{
"project_info": {
"project_number": "238923546103",
"firebase_url": "https://sample-670f7.firebaseio.com",
"project_id": "sample-670f7",
"storage_bucket": "sample-670f7.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:238923546103:android:a3653d7661f3a1f94f42f2",
"android_client_info": {
"package_name": "com.example.recorder"
}
},
"oauth_client": [
{
"client_id": "238923546103-d51sb9lr4e9ve4v10qhmjava4sv253nf.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.recorder",
"certificate_hash": "5a512901c5694ef6b387b577e3c1f0fb9bf470d5"
}
},
{
"client_id": "238923546103-i0k1lfavkjiegsusp93q6insctjbvf6p.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyB0_mG6RWAc1QUMPkg6Z9_lVoJ7JwExImo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "238923546103-i0k1lfavkjiegsusp93q6insctjbvf6p.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
也许您应该添加文件元数据以在Firebase存储中上传音频文件
setContentType(“ audio / mpeg”)
引用此链接:https://firebase.google.com/docs/storage/android/upload-files#add_file_metadata