I am using flutter v1.12.13+hotfix.8(Released in Feb 2020) and I followed the example but whenever I call AudioService.start I get the following in the Debug Console
D/FlutterEngine( 6065): Destroying.
D/FlutterEnginePluginRegistry( 6065): Destroying.
W/FlutterJNI( 6065): Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: 4
And then, all subsequent calls on AudioService are not picked up by the BackgroundService
What could be the problem?
Hi @ReaganRealones
I would suggest filling in a bug report which would give me more information useful in tracking down the problem.
Hey @ReaganRealones
I was seeing a similar issue and the Background Service was immediately stopping. To solve it I followed the Android Setup section of the README including the optional step at the end (which I hadn't done previously). Also I had not added the shrinkResources false to the build.gradle file.
It seems to be working for me now, so it's worth a shot. Please note I added this package to an exiting project that was made before Flutter 1.12 so I also followed the notes on the new project template link in the README. I had done most of it, but I doubled checked everything.
Hope this helps!
Hi @ReaganRealones , is your issue now resolved by following the Android Setup instructions?
Not sure if it's relevant but i'm going to leave it here anyways.
When i run the example (newest from github), start playing audio and then press the stop button i get this message in the console:
W/FlutterJNI(23165): Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: 31
It could be related to this issue, but there is a difference with "Tried to send a platform message / Cannot execute operation:
https://github.com/flutter/flutter/issues/28651
There are mentions in the thread that this happens when destroying the flutter engine. Maybe this message should just be ignored?
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-GB)
• Flutter version 1.17.0 at /Users/snaebjorn/development/flutter
• Framework revision e6b34c2b5c (10 days ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/snaebjorn/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] IntelliJ IDEA Community Edition (version 2018.2.4)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 29.0.4
• Dart plugin version 182.4323.44
[✓] VS Code (version 1.43.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1
[✓] Connected device (1 available)
• SM G950F • 192.168.8.174:5555 • android-arm64 • Android 9 (API 28)
• No issues found!
facing the same issue.
In the background activity, onAddQueueItem,
after some items added I get this error and further execution is stopped.
sometimes it add more items and sometimes two or three before this error.
how can I modify MainActivity.kt file? @ryanheise
@itsatifsiddiqui my guess is that your code is causing a crash or causing a call to completer.complete()
Same thing happening to me when i try to restart service after stop.
Hi everyone, the Flutter issue @snaeji referred to was updated a few days ago with some news that they may look into this soon. That issue also suggests this warning message can be ignored.
However, if you have found that audio_service stops functioning correctly after this warning message, I'll need you to fill in the bug report template which includes a link to your minimal reproduction project. Based on your minimal reproduction project, I may be able to implement a workaround in the meantime.
@ryanheise Thank you for taking the time to reply.
But as descibed by @snaeji, it was due to the call to completer.complete() on start method.
I'm getting this in onStop also.
It looks like this merge in Flutter fixed the crashes, but I'm not sure why the logging is still being triggered - that could be an issue with this plugin.
https://github.com/flutter/engine/pull/8170/commits/867905095ed969413887ce14c5714c81d648c11a
I am also having this issue, is this fixed? after stopping service cannot play.
EDIT: adding _completer.complete() in onStop method solved the issue.
I'am also getting this error when I call onStop, then the app will freeze
W/FlutterJNI(28183): Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: 62
but the example is ok for me, so I believe something in my code went wrong
@mohammadne would you be able to share a reproduction project?
the issue was because of my wrong stream implementation :
Rx.combineLatest2<List<Music>, List<MediaItem>, List<Music>>(
_audioQueueSbj.stream,
AudioService.queueStream,
(queue, mediaItems) {
if (mediaItems == null || mediaItems.isEmpty) _audioQueueSbj.add([]);
return queue;
},
).distinct();
this stream stucked into an infinite loop which was cause of freezing the application when I called onStop.
because of adding item to _audioQueueSbj inside of combineLatest2.
means this line : if (mediaItems == null || mediaItems.isEmpty) _audioQueueSbj.add([]);
but still I have the FlutterJNI was detached from native C++ log both in example and my projects.
there's no crash or freezing, but I will see that with different IDs like : 62, 51 and ...
I suspected it could be something like that. But regarding the JNI message (which should be harmless), hopefully this warning will disappear once moving to the one-isolate branch.