Java Question Save buffer in mp3

gerredtor

Active Member
Licensed User
Hello i record and save the buffer in a mp3 file, but the mp3 file is buggy...

my code to save:

B4X:
    private void runRecording() {
        final byte buf[] = new byte[mBufSize];
        mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                // stop recording
                if (!mIsRecording) {
                    mAudioRecord.stop();
                    return;
                }
                mAudioRecord.read(buf, 0, mBufSize);
              
                vr.readBuffer(buf);
              
                if(save)
                {
                    try {
                        fos.write(buf);  <------ this is a FileOutputStream
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
              
                int decibel = calculateDecibel(buf);
                // callback for return input value
                if (mVolumeListener != null) {
                    mVolumeListener.onCalculateVolume(decibel);
                }
            }
        }, 0, mSamplingInterval);
    }

the error:

java.io.IOException: Prepare failed.: status=0x1
 
Last edited:
Top