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

Not able to use custom EventChannel inside BackgroundTask #399

Closed
Mighty683 opened this issue Jul 12, 2020 · 3 comments
Closed

Not able to use custom EventChannel inside BackgroundTask #399

Mighty683 opened this issue Jul 12, 2020 · 3 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@Mighty683
Copy link

Mighty683 commented Jul 12, 2020

Which API doesn't behave as documented, and how does it misbehave?
I created my custom EventChannel to listen to event of unplugging headset to detect and stop in such situation music in my radio app. Event is working fine if it's called from main UI of application eg: state initialization of widget. But trying to use EventChannel inside scope of BackgroundAudioTask eg: onStart of task it throws error MissingPluginException

Minimal reproduction project
Situation when custom EventChannel is broken:
https://github.com/Mighty683/radio-anime-24-app/tree/Audio_service_bug_repro
https://github.com/Mighty683/radio-anime-24-app/commit/21f76ed876f2cac0b3212386c24be2562095c666

For comparison working solution:
https://github.com/Mighty683/radio-anime-24-app/tree/master
https://github.com/Mighty683/radio-anime-24-app/commit/1624a139bb7d2f0f19df32a032f4385ba1df334c

Problem is when user close app but leave Audio Manager open and playing music. Then on unplugg of headset won't stop music.

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:
Run application on Android it should appear just after API end load of data.

Error messages

The following MissingPluginException was thrown while activating platform stream on channel com.radioanime24.dev/headphones:
MissingPluginException(No implementation found for method listen on channel com.radioanime24.dev/headphones)

Expected behavior
Working EventChannel inside scope of BackgroundAudioTask or if this is not possible leave information in documentation that using MethodChannel or EventChannel is not possible inside BackgroundAudioTask.

Screenshots
If applicable, add screenshots to help explain your problem.

Runtime Environment (please complete the following information if relevant):

  • Device: Emulator / Huawei P20
  • OS: 10

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.20.0-7.0.pre, on Mac OS X 10.15.5 19F101, locale pl-PL)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.47.0)
[✓] Connected device (1 available)

• No issues found!

Additional context
I believe that this can be connected to this issue:
#129

@Mighty683 Mighty683 added 1 backlog bug Something isn't working labels Jul 12, 2020
@ryanheise
Copy link
Owner

I think this is more of a Flutter thing. You need to define your Kotlin code in a plugin rather than embed it into the main activity. Plugins get automatically registered in each registry. I suppose you can research the Java APIs and maybe figure out how to register your EventChannel listener in the right registry for the background audio task but I think it would be easier for you to put your code in a plugin and have it automatically registered.

Incidentally, the feature you are trying to implement yourself is already provided by audio_service. Why not override onAudioBecomingNoisy in the background audio task?

@Mighty683
Copy link
Author

Oh. I don't know how I missed that in documentation. I will use this feature. Sorry for bothering

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants