bdlukaa / just_audio_windows

Audio Player
8 stars 14 forks source link

Channels and platform threading error #30

Open mbfakourii opened 4 months ago

mbfakourii commented 4 months ago

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):

Smartphone (please complete the following information):

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

TonyGnk commented 4 months ago

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

bdlukaa commented 4 months ago

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

TonyGnk commented 4 months ago

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 commented 4 months ago

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

https://github.com/bdlukaa/just_audio_windows/blob/d97eb5bcc675279e777f53648d64531b72eeda39/just_audio_background/example/lib/main.dart#L63-L72

TonyGnk commented 4 months ago

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

bdlukaa commented 4 months ago

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

https://github.com/bdlukaa/just_audio_windows/blob/d97eb5bcc675279e777f53648d64531b72eeda39/just_audio_background/example/lib/main.dart#L64

TonyGnk commented 4 months ago

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

mbfakourii commented 4 months ago

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 commented 4 months ago

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

mbfakourii commented 4 months ago

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

sadjadtalakoob74 commented 4 months ago

same error

AtamyratBabayev commented 2 months ago

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 commented 2 months ago

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 commented 3 weeks ago

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