-1

How to handle next audio button pressed event and previous audio button event on flutter just audio with audio services , my audio files is encrypted , i must decrypt audio file before playing

mediaItem.add(MediaItem(id: "1", title: item.title!,artUri: Uri.file(PathHelper().pathAudio!+"name.mp3")));
_player.setFilePath(PathHelper().pathAudio!+"name.mp3");
  • mediaItem.add(MediaItem(id: "1", title: item.title!,artUri: Uri.file(PathHelper().pathAudio!+"name.mp3"))); _player.setFilePath(PathHelper().pathAudio!+"name.mp3"); when i press next button on notification audio returns beginning i must handle next button pressed event – Muhiddinxon Abduhamidov Sep 08 '22 at 06:35
  • add in question with code formatting to easily recognized – Thusitha Deepal Sep 08 '22 at 06:56
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 08 '22 at 10:24

1 Answers1

0

I will just answer the main question about handling button events (I can't answer about encryption).

To handle button events, override these methods in your audio handler:

  • skipToNext
  • skipToPrevious
  • click

The first two handle next and previous buttons in various places including the notification, while click handles button presses on a headset. Since some headsets also also have next/previous buttons, and some headset emulate next/previous by long pressing on the volume buttons, etc., click can handle multiple types of events. For this reason, click takes a parameter indicating which of the 3 types of events occurred (next, previous or play/pause).

The default implementation of click is as follows:

  Future<void> click([MediaButton button = MediaButton.media]) async {
    switch (button) {
      case MediaButton.media:
        if (playbackState.valueOrNull?.playing == true) {
          await pause();
        } else {
          await play();
        }
        break;
      case MediaButton.next:
        await skipToNext();
        break;
      case MediaButton.previous:
        await skipToPrevious();
        break;
    }
  }

(Reference: API documentation)

Ryan Heise
  • 2,273
  • 5
  • 14