Skip to content

notification controls like audio service in just_audio_background #1522

@yagnik-flunzydigital

Description

@yagnik-flunzydigital

Is your feature request related to a problem? Please describe.
Yes. I am building an audio player application that requires both an in-app player UI and a media notification with synchronized controls.

I initially used the audioservice package to get customizable notification controls. However, I faced significant and persistent synchronization issues between the notification and my just_audio player instance, especially on Android 12+. These issues made the user experience unreliable.

I then switched to just_audio_background, which solved all the synchronization problems perfectly. It works seamlessly with just_audio. The major limitation, however, is that the notification controls are fixed and cannot be customized. My application requires additional controls in the notification, such as shuffle, repeat mode, and a favorite/like button. The current implementation only shows the standard previous, play/pause, and next controls.

Describe the solution you'd like
I would like the ability to specify which controls are displayed in the media notification. A great way to implement this would be to add a new parameter to the JustAudioBackground.init() method.

This parameter, perhaps named androidControls, could accept a List of AndroidControl enums. This would allow developers to define the exact set and order of controls they need.

Here is an example of how the proposed API could look:

import 'package:just_audio_background/just_audio_background.dart';

await JustAudioBackground.init(
  androidNotificationChannelId: 'com.yourapp.channel.audio',
  androidNotificationChannelName: 'Audio Playback',
  androidNotificationOngoing: true,
  // --- PROPOSED FEATURE ---
  androidControls: [
    AndroidControl.previous,
    AndroidControl.play,
    AndroidControl.next,
    AndroidControl.stop, // Example of adding the stop control
    // It would be great to have other controls available too:
    // AndroidControl.shuffle,
    // AndroidControl.repeat,
  ],
);

To handle custom actions like "favorite", you could perhaps listen to a callback stream from the background service that emits custom event IDs.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions