Closed FireLord closed 5 months ago
The idea is that you can create your own custom handler as a subclass of CompositeAudioHandler
. You could create multiple of these, such as AnalyticsAudioHandler
and PersistingAudioHandler
. Those are not built-ins, they would be examples of custom classes you would write yourself. You can click on API documentation to read the documentation for CompositeAudioHandler
, but I will grant that it is not detailed. However, there is an example in the examples directory.
Okay with help of example I was able to achieve what I wanted. Thank you @ryanheise for quick response!
Here is code snippet for someone who's looking for same.
import 'package:audio_service/audio_service.dart';
class MainSwitchHandler extends SwitchAudioHandler {
final List
MainSwitchHandler(this.handlers) : super(handlers.first);
@override
Future
3. Then init your AudioService like this. I'm using get_it to inject here
```dart
sl.registerSingletonAsync<AudioHandler>(() async {
return AudioService.init(
builder: () => MainSwitchHandler([
AudioPlayerHandler(),
StoryPlayerHandler(),
]),
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.music.focusflow.channel.audio',
androidNotificationChannelName: 'Audio playback',
androidNotificationOngoing: true,
androidNotificationIcon: 'mipmap/ic_launcher',
),
);
});
extension AudioHandlerExtension on AudioHandler {
Future<void> switchToHandler(int? index) async {
if (index == null) return;
final AudioHandler audioHandler = sl();
await audioHandler.customAction('switchToHandler', <String, dynamic>{'index': index});
}
}
audioHandler.switchToHandler(0);
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.
Documentation request for the following page(s)
https://pub.dev/packages/audio_service
Section(s) in question
Advanced features Compose multiple audio handler classes:
_audioHandler = await AudioService.init( builder: () => AnalyticsAudioHandler( PersistingAudioHandler( MyAudioHandler())), );
Suggested improvement
There is no function related to AnalyticsAudioHandler, no proper guide to access particular handler when using the play pause function