Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get an audiosessionId from Exoplayer?

I'm trying to use Exoplayer in my project (instead of the MediaPlayer of Android). However, I have a problem: getting the id of current audio session. With traditional MediaPlayer, it's easy by calling getAudioSessionId, but Exoplayer hasn't any corresponding method. Anyone help me?

like image 996
hunghd Avatar asked Jan 25 '26 10:01

hunghd


1 Answers

As of ExoPlayer2 MediaCodecAudioTrackRenderer and PlayerControl can't be used anymore to obtain the AudioSessionId. Instead, you should set an AudioRendererEventListener on your exoPlayer instance.


EDIT:

AudioRendererEventListener is now deprecated. Use AnalyticsListener instead.

exoplayer.addAnalyticsListener(new AnalyticsListener() {
    /**
     * Called when the audio session id is set.
     *
     * @param eventTime      The event time.
     * @param audioSessionId The audio session id.
     */
    @Override
    public void onAudioSessionId(EventTime eventTime, int audioSessionId) {
         // do something with audioSessionId
    }
});
like image 171
Mdlc Avatar answered Jan 27 '26 22:01

Mdlc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!