javaandroidkotlinandroid-music-playerandroid-mediasession

How to play and pause MediaSession in Android


I'm trying to learn MediaSession, so I made an audio player app, but I didn't use MediaSession becuase I don't know how to, therefore, I can't handle the playback with headset keys, for example, hook key.

I need a simple example on how to play dummy audio with MediaSession, which has play and pause features.


Solution

  • The Universal Android Music Player Sample shows how to implement an audio media app that works across multiple form factors.

    In the full guide, there's a media session and controller section you'd probably like to read.

    You can find MediaSession implemented in the UAMP sample inside MusicService.

    Other great resources: