ysak-y / flutter_audio_capture

Package to capture audio stream buffer for flutter
MIT License
23 stars 30 forks source link

1.1.1, 1.1.2, 1.1.3 are not working on iOS #16

Closed kijka closed 1 year ago

kijka commented 1 year ago

1.1.1, 1.1.2, 1.1.3 are not working on iOS. With 1.1.0, everything is good.

As you can see in the video, the microphone notification (orange circle on the top right) disappears after some time, and there is no output from the microphone in the logs.

https://user-images.githubusercontent.com/1916984/204797656-9b828a86-b1e5-4d1b-89ca-26a25f92361f.mp4

Here is the sample code to reproduce the issue. It looks the same as the example project:

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterAudioCapture _plugin = new FlutterAudioCapture();

  @override
  void initState() {
    super.initState();
  }

  Future<void> _startCapture() async {
    await _plugin.start(listener, onError, sampleRate: 41000, bufferSize: 3000);
  }

  Future<void> _stopCapture() async {
    await _plugin.stop();
  }

  void listener(dynamic obj) {
    print(obj);
  }

  void onError(Object e) {
    print(e);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Audio Capture Plugin'),
        ),
        body: Column(children: [
          Expanded(
              child: Row(
            children: [
              Expanded(
                  child: Center(
                      child: FloatingActionButton(
                          onPressed: _startCapture, child: Text("Start")))),
              Expanded(
                  child: Center(
                      child: FloatingActionButton(
                          onPressed: _stopCapture, child: Text("Stop")))),
            ],
          ))
        ]),
      ),
    );
  }
}

tested on iPhone 13 pro, 16.1.1

srmncnk commented 1 year ago

Hi @vladsonkin. I looked at the code and came to the conclusion that probably first data does not arrive for you in time on iOS. I could not reproduce it on my SE2 though.

I added this PR, please test it out and report what happens: https://github.com/ysak-y/flutter_audio_capture/pull/19 You can add it via pubspec.yaml as a git reference.

By default on iOS you no longer wait for first data to arrive, it's a parameter however, should one want to invoke original behaviour. I also added a timeout for waiting for first data to arrive, if you want to experiment with that and extend it.

kijka commented 1 year ago

It works perfectly, thanks @srmanc Great work!

ysak-y commented 1 year ago

Hi, I published version 1.1.4 with patch from #19 . Thank you for your contribution! @srmanc and @vladsonkin . Please try it :) https://pub.dev/packages/flutter_audio_capture/versions

kijka commented 1 year ago

All good, thanks!