Hi all, we’re running into a persistent issue and would love help from the community or FlutterFlow team:
We’re using a custom action that:
Sends a text string to OpenAI’s
/v1/audio/speechendpoint for TTS.Receives MP3 bytes and saves to a local file.
Plays the file using
AudioPlayer(playerId: roleID)withDeviceFileSource.
Playback works beautifully. The problem is:
👉 We cannot reliably stop the audio using another custom action.
Here’s what we tried:
Creating a separate
stopSpeaking(playerId)action that re-creates the sameAudioPlayer(playerId: roleID)and callsawait player.stop().We store the
playerIdin a sharedFFAppState().currentPlayerIdso we’re referencing the same ID.However, the stop() call often has no effect — the audio keeps playing.
We believe this is either:
A scoping issue (new
AudioPlayer()with sameplayerIdisn't actually sharing the same instance), orA FlutterFlow runtime limitation where each custom action has its own isolated execution context, breaking shared memory.
I tried to create a singleton using custom code file, but custom actions can not leverage it and compiler always threw errors. If any one know how to may that work, please let me know.
Question:
🟡 Is there a supported way in FlutterFlow custom actions to stop a playing AudioPlayer instance from a separate action?
🟡 Does AudioPlayer(playerId: roleID) guarantee instance sharing across actions?
🟡 Is there a better FF-supported pattern (global object, singleton, or workaround) for persistent audio control?
We’ve already tried:
Defining a singleton
TTSPlayerSingleton.player— works locally but can’t be accessed across actions in FF.Using custom functions (but they don’t support side effects like audio control).
Any help or insight would be appreciated!