Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels and platform threading error #30

Open
mbfakourii opened this issue Feb 14, 2024 · 15 comments
Open

Channels and platform threading error #30

mbfakourii opened this issue Feb 14, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@mbfakourii
Copy link

Which API doesn't behave as documented, and how does it misbehave?
When the audio tries to play, the following error is given

[just_audio_windows] Called setVolume
[just_audio_windows] Called setSpeed
[just_audio_windows] Called setPitch
[just_audio_windows] Called setSkipSilence
[just_audio_windows] Called setLoopMode
[just_audio_windows] Called setShuffleMode
[just_audio_windows] Called load
[ERROR:flutter/shell/common/shell.cc(1015)] The 'com.ryanheise.just_audio.events.d5e27073-96dd-47df-bc50-39a5ebd90ea3' 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.
[ERROR:flutter/shell/common/shell.cc(1015)] The 'com.ryanheise.just_audio.data.d5e27073-96dd-47df-bc50-39a5ebd90ea3' 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.

Minimal reproduction project
n/a

To Reproduce (i.e. user steps, not code)
n/a

Expected behavior
I expected the sound to be played and not error

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome

Smartphone (please complete the following information):

  • Device: Huawei honor 10 lite
  • OS: Android 10

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.22631.3085], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.4)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.86.0)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

Additional context
n/a

@mbfakourii mbfakourii added the bug Something isn't working label Feb 14, 2024
@TonyGnk
Copy link

TonyGnk commented Feb 14, 2024

I'm getting the same error. If i try the audioplayers, the same error appears, simply with a different channel name.

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 14, 2024

Please provide a reproducible snippet. Make sure you are not calling the plugin from any isolate other than the main thread.

@TonyGnk
Copy link

TonyGnk commented Feb 16, 2024

A reproducible snippet from me:

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  @override
  initState() {
    super.initState();
    playWidgetSound();
 }

  playWidgetSound() async {
    //Player is global variable
    player.setAsset(songPath);
    player.play();
  }

  @override
  Widget build(BuildContext context){
  //Rest of the code
}

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 19, 2024

What is the value of songPath? You need to add asset:/// before the path to play an asset.

AudioSource.uri(
Uri.parse("asset:///audio/nature.mp3"),
tag: MediaItem(
id: '${_nextMediaId++}',
album: "Public Domain",
title: "Nature Sounds",
artUri: Uri.parse(
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg"),
),
),

@TonyGnk
Copy link

TonyGnk commented Feb 19, 2024

The value of songPath is assets/audio/song.mp3. It isn't an asset from the web.

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 19, 2024

You need to add asset:/// as a prefix of your path to play audios from assets.

Uri.parse("asset:///audio/nature.mp3"),

@TonyGnk
Copy link

TonyGnk commented Feb 21, 2024

Ok, the problem has been solved for me. Thank you very much.

@mbfakourii
Copy link
Author

Please provide a reproducible snippet. Make sure you are not calling the plugin from any isolate other than the main thread.

final AudioPlayer player = AudioPlayer();
duration = await player.setUrl(urlFile, preload: false);
player.play();

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 25, 2024

@mbfakourii what is the value of urlFile? For files, it is recommended to use the file: scheme.

@mbfakourii
Copy link
Author

urlFile is a web address, for example
https://example.com/1.mp3

@sadjadtalakoob74
Copy link

same error

@AtamyratBabayev
Copy link

Are there any updates here? I get the same error on very first play, then it works as expected:

[just_audio_windows] Called setVolume
[just_audio_windows] Called setSpeed
[just_audio_windows] Called setPitch
[just_audio_windows] Called setSkipSilence
[just_audio_windows] Called setLoopMode
[just_audio_windows] Called setShuffleMode
[just_audio_windows] Called load
[ERROR:flutter/shell/common/shell.cc(1038)] The 'com.ryanheise.just_audio.events.4b09e9ac-b209-4b32-9430-97ba08da1775' 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.
[ERROR:flutter/shell/common/shell.cc(1038)] The 'com.ryanheise.just_audio.data.4b09e9ac-b209-4b32-9430-97ba08da1775' 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.

On mobile it works as expected.

Flutter version

[√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.22631.3447], locale ru-RU)
    • Flutter version 3.19.5 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (6 weeks ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

@bdlukaa
Copy link
Owner

bdlukaa commented May 7, 2024

There is this issue with Flutter plug-ins on Windows. It happens with a few packages and have been known to be just a warning.

As some have reported above, the audio plays even with the error printed.

Note that this doesn't happen on all devices and not even all the time, which makes it hard to track and debug.

@amorenew
Copy link

amorenew commented Jun 11, 2024

the funny thing is that audio_player library have the same issue
bluefireteam/audioplayers#1635
I wish I knew what is needed to learn windows c++ applications but I can't find good resources for it

@moha-b moha-b mentioned this issue Sep 16, 2024
@labyte
Copy link

labyte commented Jan 14, 2025

same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants