将MP3文件上传到Firebase存储最终成为视频/ mp3文件

时间:2016-07-10 20:23:05

标签: android firebase firebase-storage

我尝试在新的Firebase存储选项中保存音频,音频设置为.mp3文件,并通过以下代码上传到Firebase:UploadTask uploadAudio = storageRef.putFile(audioUri); 问题是音频存储为视频/ mp4文件,因此MediaPlayer不会将其复制为音频,我该如何解决?

2 个答案:

答案 0 :(得分:4)

移动评论回答:

您可以向Firebase明确specify metadata when you upload the file。如果您指定setContentType("audio/mpeg"),则应将文件正确映射到MP3。

答案 1 :(得分:1)

 class func uploadAudios(data : Data,completion :  @escaping (_ succus : String )->Void){
    var url = ""
    let storage = Storage.storage()
    // Create file metadata including the content type
    let metadata = StorageMetadata()
    metadata.contentType = "audio/mpeg"
    let uploadRef = storage.reference().child("audios/\(UUID().uuidString).mp3")
    uploadRef.putData(data, metadata: nil) { metadata,
        error in
        if error == nil {
            print("successfully uploaded Audio")
            url = (metadata?.downloadURL()?.absoluteString)!
            print("AhmedRabie \(url)")
            completion(url)
        }
        else {
            print("UploadError \(String(describing: error))")
        }

    }

}