sweyer
sweyer copied to clipboard
Reacting to media play button doesn't work when Sweyer is not running
Steps to reproduce
- Make sure Sweyer is not running (force close the app).
- Trigger a
KEYCODE_MEDIA_PLAY
event orKEYCODE_MEDIA_PLAY_PAUSE
event, e.g. press the play button on a connected headset. - Observe the logcat logs.
What did you expect?
The app should be able to start from the audio_service
and start playing audio.
What happened instead?
The app does start in the background, but never plays audio. This is because the following error is thrown:
Error
I/System.out: ### onAttachedToEngine
I/System.out: ### 1 client handlers
I/System.out: ### new AudioHandlerInterface
I/System.out: ### connect
D/MediaBrowserCompat: Connecting to a MediaBrowserService.
I/System.out: ### connect returned
I/System.out: ### onAttachedToEngine completed
D/DeviceInfoPlugin: Use TaskQueues.
I/System.out: flutterEngine warmed up
I/System.out: ### onStartCommand
I/System.out: ### onMediaButtonEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PLAY_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 }
2022-06-26 17:39:10.733 6154-6154/com.nt4f04und.sweyer I/System.out: ### listener = com.ryanheise.audioservice.AudioServicePlugin$AudioHandlerInterface@8194acc
I/System.out: ### calling onClick
I/System.out: ### sending click map: {button=0}
I/System.out: ### called onClick
I/System.out: ### onGetRoot. isRecentRequest=false
I/System.out: ### onConnected
I/System.out: ### registered mediaController callback
I/System.out: ### onConnected returned
I/flutter: The Dart VM service is listening on http://127.0.0.1:45025/VEcJ_HFwVvI=/
I/flutter: ----------------FIREBASE CRASHLYTICS----------------
I/flutter: MissingPluginException(No implementation found for method retrieveSongs on channel content_channel)
I/flutter: #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
<asynchronous suspension>
#1 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:353:35)
<asynchronous suspension>
#2 ContentChannel.retrieveSongs (package:sweyer/logic/player/content_channel.dart:113:18)
<asynchronous suspension>
#3 ContentControl.refetch.<anonymous closure> (package:sweyer/logic/player/content.dart:444:33)
<asynchronous suspension>
#4 ContentControl.refetch (package:sweyer/logic/player/content.dart:441:5)
<asynchronous suspension>
#5 Future.wait.<anonymous closure> (dart:async/future.dart:521:21)
<asynchronous suspension>
#6 Future.any.onValue (dart:async/future.dart:611:5)
<asynchronous suspension>
The reason for the error is that ContentChannel
initialization is triggered by MainActivity.onCreate
, but when the app is not running and we are starting via the audio service, no MainActivity
is ever created and therefore the MethodChannel
is never registered.
The only workaround I found (suggested by https://github.com/ryanheise/audio_service/issues/399#issuecomment-657326724) is to extract the method channel into a separate plugin and use the plugin registration system to initialize the method channel under all conditions.
@nt4f04uNd do you have a better idea how to approach this?
Sweyer version
Latest on the 1.0.8
branch; c6386e62fcae56165233ab1c09e0d7f024075cc2
Android version
No response
I can confirm that extracting the content channel and pretty much all of our Java code into a plugin solves the issue.