Which API doesn't behave as documented, and how does it misbehave?
Listening to AudioService.playbackStateStream do not trigger any event when app is resumed/started from background.
Minimal reproduction project
Provide a link here using one of two options:
To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:
Error messages
no error message
Expected behavior
should trigger event when AudioService.pause() is called,
Screenshots
no ss
Runtime Environment (please complete the following information if relevant):
Flutter SDK version
Doctor summary (to see all details, run flutter doctor -v):
[鉁揮 Flutter (Channel stable, 2.0.2, on Linux, locale en_US.UTF-8)
[鉁揮 Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[鉁梋 Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[鉁揮 Android Studio
[鉁揮 Connected device (1 available)
! Doctor found issues in 1 category.
Additional context
Plugin version: audio_service: ^0.17.0-nullsafety.0
My constructor of Class class PlayerViewModel extends StateNotifier<PlayerModel>:
PlayerViewModel() : super(PlayerModel.initial()) {
if (playbackStateSubscription != null) {
playbackStateSubscription!.cancel();
}
playbackStateSubscription = AudioService.playbackStateStream.listen(
(playbackState) {
if (playbackState.playing) {
state = state.copyWith(playerState: const PlayerState.playing());
} else {
if (AudioService.running) {
state = state.copyWith(playerState: const PlayerState.paused());
} else {
state = state.copyWith(playerState: const PlayerState.stopped());
}
}
},
);
}
Minimal reproduction project
Provide a link here using one of two options:
Fork this repository and modify the example to reproduce the bug, then provide a link here.
If the unmodified official example already reproduces the bug, just write "The example".
Can you please fill in this section following the instructions? Thanks.
I have attached a sample code, if it is not sufficient I will do a simple project and provide you that. But for now, have you read my issue properly? Is this the right way to listen to the AudioService.playbackStateStream?
if it is not sufficient
If you skip what is required by the instructions, then it is not sufficient, so yes you must fill in that section as per the instructions, thanks.
I am sorry, I was not able to produce the error in minimal code. It works well with single page app with controls only. Maybe this is my fault but I am unable to figure it out.
But below is my findings, I think this is due to unable to connect with AudioServiceWidget properly or I am using AudioServiceWidget in a wrong way.
I have above described problem with:
```
MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: AppTheme().defaultTheme,
themeMode: ThemeMode.dark,
title: 'Voice Of Blessing',
initialRoute: introScreen == 0 || introScreen == null ? 'intro' : '/',
routes: {
'intro': (context) => IntroPage(),
'/': (context) => AuthWidget(),
'/loginPage': (context) => LoginPage(),
'/signupPage': (context) => SignupPage(),
'/homePage': (context) => AudioServiceWidget(child: HomePage()),
'/aboutPage': (context) => AboutPage(),
'/contactPage': (context) => ContactPage(),
},
);
With this gives not connected exception
D/MediaBrowserCompat(14265): Connecting to a MediaBrowserService.
E/flutter (14265): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Exception: Not connected
E/flutter (14265): #0 AudioService.start.
package:audio_service/audio_service.dart:798
E/flutter (14265): #1 AudioService.start.
package:audio_service/audio_service.dart:797
E/flutter (14265): #2 _AsyncTaskQueue._process
package:audio_service/audio_service.dart:1988
E/flutter (14265):
E/flutter (14265):
MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: AppTheme().defaultTheme,
themeMode: ThemeMode.dark,
title: 'Voice Of Blessing',
initialRoute: introScreen == 0 || introScreen == null ? 'intro' : '/',
routes: {
'intro': (context) => IntroPage(),
'/': (context) => AudioServiceWidget(child: AuthWidget()),
'/loginPage': (context) => LoginPage(),
'/signupPage': (context) => SignupPage(),
'/homePage': (context) => HomePage(),
'/aboutPage': (context) => AboutPage(),
'/contactPage': (context) => ContactPage(),
},
);
With single page work fine:
MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: AppTheme().defaultTheme,
themeMode: ThemeMode.dark,
title: 'Voice Of Blessing',
home: AudioServiceWidget(
child: Scaffold(
body: HomePage(),
),
),
);
```
Almost all of the time when someone doesn't provide a minimal reproduction project, it turns out to be a bug in their own app rather than a bug in the plugin, due to not correctly following the documentation (e.g. missing one of the setup or init instructions, or calling methods in the wrong order). I know that it takes time and effort to create a minimal reproduction project, but I can tell you that it takes a lot more time and effort to fix a bug, so I think it is fair that if you want me to spend time fixing the bug, you had better be sure it is not a bug in your app, and basically give me your entire app and ask me to debug it. What you need to do is take out everything that is unnecessary to demonstrate the bug so that you can narrow it down to what is definitely a bug in the plugin. I don't want to look at the way you have used 41 different API calls together to see if any of them are called in the wrong order, please reduce the scope down to the minimal.
Also as per the instructions:
Note: Issues that don't follow these instructions will be closed,
therefore please read them carefully.
- A bug report must demonstrate a bug in the plugin, and not merely a
bug in your app. Understand that this plugin WILL throw exceptions
or otherwise misbehave if not used in accordance with the
documentation. In order to verify that you have indeed found a bug,
you will need to make a reference to the documentation in order to
explain how the actual behaviour you experienced is different from
the behaviour that was documented.
I will close this issue, as I feel it is almost certain that you have missed a setup or initialisation, or called methods in the wrong order, etc, so you should go through everything you have done and check that each is in accordance with the documentation, not just playbackStateStream.
Sorry to hear that from you. I have already mentioned when it works and when it don't. It is cleat that I have having problem using AudioServiceWidget in my routes because instruction is not clear. I gave the full app not to debug but because bug is not produced with simpler navigation app like single page app and I already mentioned there.
Being maintainer of this plugins you may read my whole description and try to help. But no you only need minimal code that reproduce bug.
Tell me if below method is what should be done while using routes, and initialRoute instead of home. And I will try to figure out about this problem. Thanks.
MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: AppTheme().defaultTheme,
themeMode: ThemeMode.dark,
title: 'Voice Of Blessing',
initialRoute: introScreen == 0 || introScreen == null ? 'intro' : '/',
routes: {
'intro': (context) => IntroPage(),
'/': (context) => AudioServiceWidget(child: AuthWidget()),
'/loginPage': (context) => LoginPage(),
'/signupPage': (context) => SignupPage(),
'/homePage': (context) => HomePage(),
'/aboutPage': (context) => AboutPage(),
'/contactPage': (context) => ContactPage(),
},
);
Being maintainer of this plugins you may read my whole description and try to help. But no you only need minimal code that reproduce bug.
Yes I need you to follow the instructions. You may disagree, but please don't submit an issue that ignores or disregards what I have requested. I am very willing to help people with issues, but I am less inclined to help people who do not have any consideration for my instructions, which have been put in place to help me manage what is a very difficult job.
It is not actually my job to fix your bug. But it's quite possible that the documentation isn't clear. If that is the case, there are ways to contribute to help this project better, but it requires as much from you as it requires from me. One person cannot possibly process this many bugs, feature requests and documentation requests, so I need everybody's help to do their fair share, and one way of doing that is by doing the initial investigation yourself to narrow it down to a bug. That is basically the exercise in creating your minimal reproduction project.
Now that you've narrowed it down, you can either create a minimal reproduction project if it's a bug, or you can submit a documentation request to improve the quality of this project. In each case, there are instructions on how to do so in a way that reduces the burden on the maintainer.
It sounds like you have narrowed it down to a documentation issue. Would you consider submitting a documentation request if you have a clear idea that that is the issue? Or alternatively if you just wish to ask a question on the best way to handle navigation of multiple screens with AudioServiceWidget, you might also consider asking a question on StackOverflow. Questions on StackOverflow can sometimes also help inform me of ways in which the documentation can be improved.
I wrapped MaterialApp with AudioServiceWidget and the problem was gone. I hope I will not get other problem with this plugin. It becomes really hard to solve problem when devs don't try to understand us. I was hopping you will look into my problem and try to help me. Little help, instruction or correction can make huge difference for those who don't have enough knowledge. Any way thanks for the awesome plugins just audio and audio service.
return AudioServiceWidget(
child: MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: AppTheme().defaultTheme,
themeMode: ThemeMode.dark,
title: 'Voice Of Blessing',
initialRoute: introScreen == 0 || introScreen == null ? 'intro' : '/',
routes: {
'intro': (context) => IntroPage(),
'/': (context) => AuthWidget(),
'/loginPage': (context) => LoginPage(),
'/signupPage': (context) => SignupPage(),
'/homePage': (context) => HomePage(),
'/aboutPage': (context) => AboutPage(),
'/contactPage': (context) => ContactPage(),
},
),
);
I wrapped
MaterialAppwithAudioServiceWidgetand the problem was gone.
It must go around the root route. I apologise if the documentation is not clear about that, but AudioServiceWidget will be gone in the 0.18.0 release which is where my focus is at the moment.
It becomes really hard to solve problem when devs don't try to understand us.
Likewise it becomes really hard to maintain this project when people disregard the instructions for submitting issues. I suppose it is human nature. It's easier for you to skip required sections of the bug report, and harder for me to take up the slack. But if you want to open new issues in the future (and I hope you will), please take the instructions seriously next time. It is very difficult for me to maintain this project otherwise.