flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

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

Open jtdLab opened this issue 1 year ago • 17 comments

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.

jtdLab avatar Jan 01 '24 13:01 jtdLab

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.

github-actions[bot] avatar Mar 05 '24 01:03 github-actions[bot]

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

quyetvu95 avatar May 31 '24 07:05 quyetvu95

@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.

Larpoux avatar May 31 '24 08:05 Larpoux

@Larpoux Thank you for responding.

quyetvu95 avatar May 31 '24 09:05 quyetvu95

@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?

jtdLab avatar May 31 '24 11:05 jtdLab

  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 avatar Jun 04 '24 16:06 Larpoux

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 👀

Larpoux avatar Jun 04 '24 17:06 Larpoux

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

jtdLab avatar Jun 04 '24 18:06 jtdLab

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 🙇

willsmanley avatar Jun 08 '24 20:06 willsmanley

@willsmanley :

  • Android is ok. Please let me know if any problem.
  • On iOS, last version (9.4.19) is probably OK for StartPlayerToStream(). Please let me know if any problem.
  • On iOS RecordToStream() is buggy. I am currently working on it. But this is hard, because iOS has many bugs in the Audio Engine support.
  • On iOS, PlayFromMic() is probably buggy. I will work on it when Record To Stream will work correctly.

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

Larpoux avatar Jun 08 '24 20:06 Larpoux

@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.

jtdLab avatar Jun 08 '24 21:06 jtdLab

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 avatar Jun 08 '24 21:06 Larpoux

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

Larpoux avatar Jun 08 '24 21:06 Larpoux

@jtdLab :

  • Do you play something before your record to stream?
  • What are the sample rate, the buffer size and the number of channels you use in your app?

Larpoux avatar Jun 08 '24 21:06 Larpoux

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 ...

Larpoux avatar Jun 09 '24 06:06 Larpoux

Thank you so much , i will try

quyetvu95 avatar Jun 09 '24 06:06 quyetvu95

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

willsmanley avatar Jun 11 '24 06:06 willsmanley