anarchuser / mic_stream

Flutter plugin to get an infinite audio stream from the microphone
https://pub.dev/packages/mic_stream
GNU General Public License v3.0
100 stars 68 forks source link

unresponsive example app #78

Closed mattmattkim closed 11 months ago

mattmattkim commented 11 months ago

Firstly, thanks for putting this package together!

I'm new to Flutter development. I'm trying to run the example app on my device and it seems to work but the UI is unresponsive. I noticed the following logs on Xcode:

Thread Performance Checker: -[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness
PID: 2123, TID: 861217
Backtrace

and

[VERBOSE-2:shell.cc(1004)] The 'aaron.code.com/mic_stream' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

My flutter version:

Flutter 3.13.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 12fccda598 (8 days ago) • 2023-09-19 13:56:11 -0700
Engine • revision bd986c5ed2
Tools • Dart 3.1.2 • DevTools 2.25.0
mattmattkim commented 11 months ago

I had put a print statement in _calculateWaveSamples and this was the source of the unresponsiveness. That said, Xcode still complains with the first error message, which feels like crucial? Unfortunately I'm unfamiliar with native iOS.

anarchuser commented 11 months ago

I had put a print statement in _calculateWaveSamples and this was the source of the unresponsiveness. That said, Xcode still complains with the first error message, which feels like crucial? Unfortunately I'm unfamiliar with native iOS.

As far as I understand Apple's documentation startRunning is a blocking call and should therefore rather be dispatched asynchronously or executed on another thread instead of executing it synchronously on the main thread. It should have no further effect once recording started. That said, the only notable effect of not executing it asynchronously might be a split-second freeze of your app when you start recording. I'm not exactly sure how well the iOS backend is implemented, or how Flutter interfaces with the native platform. The starting of an audio stream should happen asynchronously already in theory. If you have the feeling this is not the case, feel free to reopen.