Firebase存储,无法播放录制的音频消息。在新条目上覆盖旧注册。如何解决?

问题描述 投票:0回答:1

我正在尝试实现一个聊天系统,并可能发送语音消息。这是我的一点逻辑:维护按钮并传递其消息。之后,释放按钮,然后消息将保存在Firestore存储中。我的录音效果很好,但是遇到了两个障碍:在新条目上,上一个条目被覆盖,我希望在Firenase存储中具有语音消息的完整列表。另外录音后,我无法打开声音。有人可以救我吗?

enter image description here

这是我的代码:Oncreate Methode

fileName = Environment.getExternalStorageDirectory().getAbsolutePath();
        fileName += "/recored_audio.3gp" ;
        btnrecoder.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    startRecording();
                    btnrecoder.setText(" Recording start...");
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    stopRecording();
                }
                return  true;
            }
        });

Out of the onCreate  :

    private void startRecording() {
        MediaRecorder  recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setOutputFile(fileName);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            try {
                recorder.prepare();
            } catch (IOException e) {
                Log.e(LOG_TAG, "prepare() failed" + e.getMessage());
            }

            recorder.start();
        }

        private void stopRecording() {
            recorder = new MediaRecorder();

            recorder.release();
            try{
                recorder.stop();
            }catch(RuntimeException stopException){
                //handle cleanup here
                Log.d(TAG," message derreure " + stopException.getMessage());
            }
            recorder = null;
            uploadAudio();

        }


        private void uploadAudio(){

            StorageReference fii = storageReference.child("Audio").child("new audio.3gp");
            Uri uri = Uri.fromFile(new File(fileName));
            fii.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    btnrecoder.setText("Uploading finished");
                    Toast.makeText(FriendList.this, "Vocal Save to db storage", Toast.LENGTH_SHORT).show();
                }
            });
        }

有些类似的问题没有得到具体的答案

android google-cloud-firestore firebase-storage voice-recording
1个回答
1
投票

正如我在这里摆在Unable to play audio in firebase storage sent from android app上,

您的问题可能是由MediaRecorder引起的。我发现输出格式应该设置为AAC。然后浏览器将能够播放它。当我尝试使用React JS播放Android中MediaRecorder捕获的音频时遇到了这个问题,并且尝试了多种格式(.3gp,.mp4,.wav),但这是唯一起作用的格式。我怀疑还有其他。

所以:

mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
© www.soinside.com 2019 - 2024. All rights reserved.