Skip to content

[Android] Stop does not complete when called immediately after startStream #435

@Goolpe

Description

@Goolpe

Package version

  • record: ^5.2.0 (tried with 5.1.2 - same problem)

Environment

  • OS: Android
  • Device: Emulator android-arm64 Pixel 4 API 34 / Samsung A54 / Xiaomi 12T

Describe the bug

We need to have opportunity to stop the recorder immediately after the start.
iOS works fine, but android has the problem with it.
If we try to stop immediately after startStream - stop does not complete
Tried to add 50ms delay before the stop, but it doesn't work for all devices.
This issue seems very similar, but fix didn't help

To Reproduce

Steps to reproduce the behavior:

  1. Run the project with this code
void main() {
  runApp(_App());
}

class _App extends StatelessWidget {
  const _App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: _TestRecorder(),
    );
  }
}

class _TestRecorder extends StatefulWidget {
  const _TestRecorder({super.key});

  @override
  State<_TestRecorder> createState() => _TestRecorderState();
}

class _TestRecorderState extends State<_TestRecorder> {
  final _recorder = AudioRecorder();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            print('START');
            await _recorder.startStream(const RecordConfig(
              encoder: AudioEncoder.pcm16bits,
              sampleRate: 16000,
              numChannels: 1,
              noiseSuppress: true,
              androidConfig: AndroidRecordConfig(manageBluetooth: false),
            ));

            print('START FINISHED');

            await _recorder.stop();

            print('STOP FINISHED');
          },
          child: const Text('TEST'),
        ),
      ),
    );
  }
}
  1. Tap 'test' button
  2. 'STOP FINISHED' doesn't appear

Expected behavior

Should stop like in iOS

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