What is the Android MediaPlayer Audio Recording ID?

As indicated in the header, what does the identifier of an audio tag of MediaPlayer objects refer to? Initially, I intend to get the int resource identifier for the my MediaPlayer audio resource. But I could not find a way to do this.

However, I came across this getAudioSessionId () method, and I was wondering if this was a function looking for.

+4
source share
2 answers

The Android system tracks the current playback or recording sounds (audio sessions), and other services can connect to them, referring to their audio session identifier. The system mix (what comes out of the speakers) has an audio session identifier of 0.

In short, this is not what you are looking for if you do not want to create a visualizer.

EDIT: Also, for those trying to use getAudioSessionID() from AudioRecord with Visualizer or something else, this does not work.

+5
source

From the AudioManager.generateAudioSessionId documentation:

An audio session identifier is a unique system identifier for a set of audio streams (one or more mixed together).

The main use of an audio messaging identifier is to associate sound effects with audio players such as MediaPlayer or AudioTrack: all audio effects sharing the audio session identifier will be applied to mixed audio content that share the same audio session.

From MediaPlayer.setAudioSessionId Document :

... if an audio session identifier is provided when creating the sound effect, this effect will be applied only to the audio content of the media players within the same audio session, and not the output mix. When created, the MediaPlayer instance automatically generates its own audio session I would. However, you can force this player to be part of an existing audio recording by calling this method. This method must be called before one of the overloaded setDataSource methods.

To create a new audio session identifier:

 AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int audioSessionId = audioManager.generateAudioSessionId(); 

AudioManager.generateAudioSessionId() can return AudioManager.ERROR .

So check it out before assigning it to MediaPlayer :

 if (audioSessionId != AudioManager.ERROR) { mediaPlayer.setAudioSessionId(audioSessionId); } 

Also :

Please note that the audio session identifier is 0 only if there was a problem creating MediaPlayer.

+1
source

All Articles