Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
850 stars 553 forks source link

[BUG]: Platform channel messages not sent on platform thread #1003

Open jtdLab opened 5 months ago

jtdLab commented 5 months ago

When using latest flutter_sound i get a warning:

The 'com.dooboolab.flutter_sound_recorder' 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.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 365 days with no activity. Leave a comment or this will be closed in 7 days.

quyetvu95 commented 4 weeks ago

This error appears on iOS when recording to stream. I have encountered a similar error.

Larpoux commented 4 weeks ago

@quyetvu95 , @jtdLab RecordToStream() and PlayFromStream() are very important Flutter Sound features that I really want to support well. Unfortunately the last versions of Flutter Sound have those functions broken on iOS. I spent a few days working on that but I gave up because I don't have enough time to spend on Flutter Sound maintenance.

I am actually working on a new Flutter Plugin (τ = Tau) that I will use on iOS for Streams Features. This is really a very big job and don't expect that I rewrite the iOS stuff soon. Perhaps someone else should look to this bug.

Note: I have never worked with Flutter Sound with Isolates. If you use Isolates I am not surprised that you have some problems. Perhaps this is not very difficult to fix ? Someone should work on that.

quyetvu95 commented 4 weeks ago

@Larpoux Thank you for responding.

jtdLab commented 4 weeks ago

@quyetvu95 , @jtdLab RecordToStream() and PlayFromStream() are very important Flutter Sound features that I really want to support well. Unfortunately the last versions of Flutter Sound have those functions broken on iOS. I spent a few days working on that but I gave up because I don't have enough time to spend on Flutter Sound maintenance.

I am actually working on a new Flutter Plugin (τ = Tau) that I will use on iOS for Streams Features. This is really a very big job and don't expect that I rewrite the iOS stuff soon. Perhaps someone else should look to this bug.

Note: I have never worked with Flutter Sound with Isolates. If you use Isolates I am not surprised that you have some problems. Perhaps this is not very difficult to fix ? Someone should work on that.

What is the last stable version in this regards?

Larpoux commented 3 weeks ago
  1. For the Isolates problem : I have never worked on Isolates. I am not surprised that it does not work, because all the plugin stuff must run on the main thread. Probably you will have to handle Flutter Sound in the main Isolate, and communicate to it from other Isolates if you really need to call Flutter Sound from secondary Isolates.
  2. For the problem with iOS and Streams : I can do something to fix it next few weeks if you really insist and if this is urgent to fix that. This will be a temporary patch, for Flutter Sound 9.x. You must understand that if I work on Flutter Sound maintenance, it will add delay to the date when I will release 10.0, with all the nice stuff fixed correctely on iOS
Larpoux commented 3 weeks ago

I decide to release a v10.0 beta soon (within a few weeks). It will fix the iOS issue with record to Streams. Just a little bit of patience 👀

jtdLab commented 3 weeks ago

No hurry take your time. You do great work thanks for that.

willsmanley commented 2 weeks ago

Does anyone know the last version that worked with streams? I will post back here if I find out.

Thank you for the amazing package @Larpoux 🙇

Larpoux commented 2 weeks ago

@willsmanley :

Debugging on iOS is very hard, because of the Apple bugs on Audio Engine.

jtdLab commented 2 weeks ago

@willsmanley

Does anyone know the last version that worked with streams? I will post back here if I find out.

Thank you for the amazing package @Larpoux 🙇

Im currently using 9.4.13 where recording to stream works well for me on both platforms.

Larpoux commented 2 weeks ago

Im currently using 9.4.13 where recording to stream works well for me on both platform

This is interesting. I will look what has been changed since 9.4.13.

Actually on my dev source, I am to the point where RecordToStream works only after having run a player. Do you play something before your record to stream?

Larpoux commented 2 weeks ago

A dummy startPlayer () and stopPlayer() is enough for having the RecordToStream working correctly. Probably it initializes a variable in Apple code

Larpoux commented 2 weeks ago

@jtdLab :

Larpoux commented 2 weeks ago

Hi, guys and girls

Flutter Sound 9.4.20 is released. All the Streams related features probably work correctly. Please let me know if you have problems.

PlayFromMic does not work on iOS. This is probably something simple to fix. But I wonder if this function is really needed : it was a try to have something with a very low latency. In fact this function has not a better latency than a regular loop between player and recorder. I suggest to remove this function if you don't need it. It will be a bit of less maintenance. Let me know what you think ...

quyetvu95 commented 2 weeks ago

Thank you so much , i will try

willsmanley commented 2 weeks ago

wow you are a serious badass for getting this working so quickly!