Search code examples
javaandroidkotlinandroid-music-playerandroid-mediasession

How to play and pause MediaSession in Android


I'm trying to learn MediaSessions. I did a lot of research for music player which has MediaSession to learn how is it working. I found nothing about MediaSession. All music apps examples on youtube doesn't have MediaSession. I'm new in android and I did a music app but I didn't use MediaSession thefore I can't handle with headset keys, for example hook key . I really want to learn proper way to make an audio app.

Could you give a sample which is playing dummy audio with MediaSession and contains play and pause features please. All I need a sample Thank you.


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: