llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
243 stars 204 forks source link

Error on android 8 and 9: Failed to stop the muxer #326

Closed mniiinm closed 5 months ago

mniiinm commented 5 months ago

Package version [5.0.5]

Environment

many of my users who have Android 8 or 9 have reported that the app crashes when recording audio. based of logs of appcenter, i get this errors for android 8 and 9. java.lang.IllegalStateException: Failed to stop the muxer Stack traces: android.media.MediaMuxer.nativeStop MediaMuxer.java android.media.MediaMuxer.stop MediaMuxer.java:454 m6.d.b o6.c.g o6.c.onOutputBufferAvailable android.media.MediaCodec$EventHandler.handleCallback MediaCodec.java:1699 android.media.MediaCodec$EventHandler.handleMessage MediaCodec.java:1646 android.os.Handler.dispatchMessage Handler.java:106 android.os.Looper.loop Looper.java:201 android.app.ActivityThread.main ActivityThread.java:6831 java.lang.reflect.Method.invoke Method.java com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:547 com.android.internal.os.ZygoteInit.main ZygoteInit.java:927

llfbandit commented 5 months ago

You can try to upgrade the package to latest. If it does not solve your issue, you can use the legacy recorder as a workaround (also from latest version).

mniiinm commented 5 months ago

I tested the latest version, and the same error still occurred, but the issue was resolved using the legacy recorder.

llfbandit commented 5 months ago

OK so can you send me the stack trace de-obfuscated? There's definitely something to fix for older devices/apis

mniiinm commented 5 months ago

ofcourse, this is full stack trace:

W/VideoCapabilities(17505): Unrecognized profile 4 for video/hevc I/VideoCapabilities(17505): Unsupported profile 4 for video/mp4v-es I/OMXClient(17505): IOmx service obtained W/ExtendedACodec(17505): Failed to get extension for extradata parameter I/OMXClient(17505): IOmx service obtained W/ExtendedACodec(17505): Failed to get extension for extradata parameter I/MediaCodec(17505): MediaCodec will operate in async mode E/Utils (17505): csd0 too small E/ExtendedUtils(17505): csd0 too small I/MPEG4Writer(17505): limits: 4294967295/0 bytes/us, bit rate: -1 bps and the estimated moov size 3191 bytes I/MPEG4Writer(17505): setStartTimestampUs: 0 I/MPEG4Writer(17505): Earliest track starting time: 0 W/MPEG4Writer(17505): 0-duration samples found: 1 E/MPEG4Writer(17505): do not support out of order frames (timestamp: 0 < last: 64000 for Audio track E/MPEG4Writer(17505): Dumping Audio track's last 10 frames timestamp and frame type E/MPEG4Writer(17505): I/MPEG4Writer(17505): Received total/0-length (4/0) buffers and encoded 3 frames. - Audio I/MPEG4Writer(17505): Audio track drift time: 0 us E/MediaAdapter(17505): pushBuffer called before start

E/AudioRecorder(17505): writeSampleData returned an error E/AudioRecorder(17505): java.lang.IllegalStateException: writeSampleData returned an error E/AudioRecorder(17505): at android.media.MediaMuxer.nativeWriteSampleData(Native Method) E/AudioRecorder(17505): at android.media.MediaMuxer.writeSampleData(MediaMuxer.java:682) E/AudioRecorder(17505): at com.llfbandit.record.record.container.MuxerContainer.writeSampleData(MuxerContainer.kt:29) E/AudioRecorder(17505): at com.llfbandit.record.record.encoder.MediaCodecEncoder.onOutputBufferAvailable(MediaCodecEncoder.kt:101) E/AudioRecorder(17505): at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1707) E/AudioRecorder(17505): at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1654) E/AudioRecorder(17505): at android.os.Handler.dispatchMessage(Handler.java:107) E/AudioRecorder(17505): at android.os.Looper.loop(Looper.java:198) E/AudioRecorder(17505): at android.app.ActivityThread.main(ActivityThread.java:6729) E/AudioRecorder(17505): at java.lang.reflect.Method.invoke(Native Method) E/AudioRecorder(17505): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AudioRecorder(17505): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

D/MPEG4Writer(17505): Audio track stopping. Stop source D/MPEG4Writer(17505): Audio track source stopping D/MPEG4Writer(17505): Audio track source stopped D/MPEG4Writer(17505): Audio track stopped. Stop source D/MPEG4Writer(17505): Stopping writer thread D/MPEG4Writer(17505): 0 chunks are written in the last batch D/MPEG4Writer(17505): Writer thread stopped D/AndroidRuntime(17505): Shutting down VM E/AndroidRuntime(17505): FATAL EXCEPTION: main

E/AndroidRuntime(17505): java.lang.IllegalStateException: Failed to stop the muxer E/AndroidRuntime(17505): at android.media.MediaMuxer.nativeStop(Native Method) E/AndroidRuntime(17505): at android.media.MediaMuxer.stop(MediaMuxer.java:454) E/AndroidRuntime(17505): at com.llfbandit.record.record.container.MuxerContainer.stop(MuxerContainer.kt:19) E/AndroidRuntime(17505): at com.llfbandit.record.record.encoder.MediaCodecEncoder.internalStop(MediaCodecEncoder.kt:55) E/AndroidRuntime(17505): at com.llfbandit.record.record.encoder.MediaCodecEncoder.onOutputBufferAvailable(MediaCodecEncoder.kt:112) E/AndroidRuntime(17505): at android.media.MediaCodec$EventHandler.handleCallback(MediaCodec.java:1707) E/AndroidRuntime(17505): at android.media.MediaCodec$EventHandler.handleMessage(MediaCodec.java:1654) E/AndroidRuntime(17505): at android.os.Handler.dispatchMessage(Handler.java:107) E/AndroidRuntime(17505): at android.os.Looper.loop(Looper.java:198) E/AndroidRuntime(17505): at android.app.ActivityThread.main(ActivityThread.java:6729) E/AndroidRuntime(17505): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(17505): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AndroidRuntime(17505): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I/Process (17505): Sending signal. PID: 17505 SIG: 9 Lost connection to device.

llfbandit commented 5 months ago

Version 5.1.1 has been released to fix this. Feedback welcomed!