Skip to content

AudioRecorder produces empty or corrupted .opus / .mp4 files with duration 0s (possible premature stop or flush issue) after updating from 5.2.0 to 6.1.2 #556

@MazenxELGayar

Description

@MazenxELGayar

🐛 AudioRecorder Produces 0-Second (Corrupted) Recordings after updating from 5.2.0 to 6.1.2

When using the AudioRecorder from the record package inside a Flutter app, the resulting recorded file occasionally has a 0-second duration and appears to be corrupted.

The encoder initializes successfully (AAC LC, Opus, and WAV all tested), but the output file contains only headers and no valid audio data.


🧩 Steps to Reproduce

  1. Create and start the recorder:

    final filePath =
        '${tempDir.path}/temp.${DateTime.now().millisecondsSinceEpoch}.wav';
    final recorder = AudioRecorder();
    await recorder.start(
      RecordConfig(encoder: AudioEncoder.opus),
      path: filePath,
    );
  2. Wait a few seconds.

  3. Stop the recording:

    await recorder.stop();
  4. Attempt to play or inspect the recorded file — it’s very small (~6–8 KB) and reports 0s duration.


✅ Expected Behavior

The file should contain valid audio data of the correct (non-zero) duration.


❌ Actual Behavior

  • Encoder logs indicate successful initialization:

    D/CCodec (17780): allocate(c2.android.opus.encoder)
    I/CCodecConfig(17780): query failed after returning 9 values (BAD_INDEX)
    D/CCodecBufferChannel: [c2.android.opus.encoder#56] start: updating output delay 0
    
  • File path is correctly created:

    /data/user/0/com.doctor.voice.patientDev/cache/temp.1760713610632.opus
    
  • But playback duration logs show:

    ! Audio duration is too small 0s — possibly corrupted
    

🧠 Environment

Key Value
Flutter SDK 3.35.4
Android 12
Device Poco X3 NFC
Permissions Microphone (granted)
Encoders Tested Opus, AAC LC, WAV

Dependencies:

record: ^6.1.2
record_android: ^1.4.3
just_audio: ^0.10.5
audio_session: ^0.2.2
audioplayers: ^6.5.1
voice_message_package: ^2.2.1

Old Dependencies:

record: ^5.2.0
record_android: ^1.3.0
audioplayers: ^6.1.0
just_audio: ^0.10.3
audio_session: ^0.2.2
voice_message_package: ^2.2.1


🧱 Relevant Code (Simplified)

abstract class BaseRecordingCubit extends Cubit<BaseRecordingState> {
  final AudioRecorder recorder = AudioRecorder();
  String? filePath;

  Future<void> startRecording() async {
    if (await recorder.hasPermission()) {
      filePath =
          '${(await getTemporaryDirectory()).path}/temp.${DateTime.now().millisecondsSinceEpoch}.opus';
      await recorder.start(
        RecordConfig(encoder: AudioEncoder.opus),
        path: filePath!,
      );
    }
  }

  Future<void> stopRecording() async {
    if (await recorder.isRecording()) {
      await recorder.stop();
    }
  }
}

📋 Logs

V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
D/AudioRecord(21075): set(): inputSource 0, sampleRate 44100, format 0x1, channelMask 0xc, frameCount 3552, notificationFrames 0, sessionId 0, transferType 0, flags 0, attributionSource AttributionSourceState{pid: -1, uid: 11052, packageName: com.doctor.voice.patientDev, attributionTag: (null), token: , renouncedPermissions: [], next: []}uid -1, pid -1,isIsolated:0
D/AudioManager(21075): dispatching onAudioFocusChange(-1) to android.media.AudioManager@9ec5224com.llfbandit.record.record.recorder.AudioRecorder$$ExternalSyntheticLambda0@4eb93a1
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(21075): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(21075): cleanDrmObj: mDrmObj=null mDrmSessionId=null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions