Search code examples
androidandroid-mediaplayerandroid-resources

What does the Android MediaPlayer audio session ID refer to?


As the title states, what does the MediaPlayer objects audio session ID refer to? Originally, I intend to retrieve the int resource ID of the audio resource my MediaPlayer is playing. But I couldn't find a method for that.

However, I stumbled upon this method getAudioSessionId() and I was wondering if that was the function I was looking for.


Solution

  • The android system keeps track of currently playing or recording sounds (audio sessions) and other services can hook into them by referencing their audio session ID. The system mix (what comes out of the speakers) has an audio session ID of 0.

    The system mix audio session ID 0 is deprecated now so you have to use getAudioSessionId().

    In short, that's not what you're looking for unless you want to build a visualizer.

    EDIT: Also, to anyone trying to use the getAudioSessionID() from AudioRecord with a Visualizer or something else, that doesn't work.