AudioRouting
  public
  
  
  
  interface
  AudioRouting
  
  
  
| android.media.AudioRouting | 
AudioRouting defines an interface for controlling routing and routing notifications in AudioTrack and AudioRecord objects.
Summary
Nested classes | |
|---|---|
        
        
        
        
        interface | 
      
        AudioRouting.OnRoutingChangedListener
        Defines the interface by which applications can receive notifications of routing
 changes for the associated   | 
    
Public methods | |
|---|---|
        abstract
        
        
        
        
        void
     | 
  
    
      
      addOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener, Handler handler)
      
      
        Adds an   | 
  
        abstract
        
        
        
        
        AudioDeviceInfo
     | 
  
    
      
      getPreferredDevice()
      
      
        Returns the selected output/input specified by   | 
  
        abstract
        
        
        
        
        AudioDeviceInfo
     | 
  
    
      
      getRoutedDevice()
      
      
        Returns an   | 
  
        
        default
        
        
        
        List<AudioDeviceInfo>
     | 
  
    
      
      getRoutedDevices()
      
      
        Returns a List of   | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener)
      
      
        Removes an   | 
  
        abstract
        
        
        
        
        boolean
     | 
  
    
      
      setPreferredDevice(AudioDeviceInfo deviceInfo)
      
      
        Specifies an audio device (via an   | 
  
Public methods
addOnRoutingChangedListener
public abstract void addOnRoutingChangedListener (AudioRouting.OnRoutingChangedListener listener, Handler handler)
Adds an AudioRouting.OnRoutingChangedListener to receive notifications of routing
 changes on this AudioTrack/AudioRecord.
| Parameters | |
|---|---|
listener | 
        
          AudioRouting.OnRoutingChangedListener: The AudioRouting.OnRoutingChangedListener interface to receive
 notifications of rerouting events. | 
      
handler | 
        
          Handler: Specifies the Handler object for the thread on which to execute
 the callback. If null, the Handler associated with the main
 Looper will be used. | 
      
getPreferredDevice
public abstract AudioDeviceInfo getPreferredDevice ()
Returns the selected output/input specified by setPreferredDevice(AudioDeviceInfo). Note that this
 is not guaranteed to correspond to the actual device being used for playback/recording.
| Returns | |
|---|---|
AudioDeviceInfo | 
        |
getRoutedDevice
public abstract AudioDeviceInfo getRoutedDevice ()
Returns an AudioDeviceInfo identifying the current routing of this
 AudioTrack/AudioRecord.
 Note: The query is only valid if the AudioTrack/AudioRecord is currently playing.
 If it is not, getRoutedDevice() will return null.
| Returns | |
|---|---|
AudioDeviceInfo | 
        |
getRoutedDevices
public List<AudioDeviceInfo> getRoutedDevices ()
Returns a List of AudioDeviceInfo identifying the current routing of this
 AudioTrack/AudioRecord.
 Note: The query is only valid if the AudioTrack/AudioRecord is currently playing.
 If it is not, getRoutedDevices() will return an empty List.
| Returns | |
|---|---|
List<AudioDeviceInfo> | 
        This value cannot be null. | 
      
removeOnRoutingChangedListener
public abstract void removeOnRoutingChangedListener (AudioRouting.OnRoutingChangedListener listener)
Removes an AudioRouting.OnRoutingChangedListener which has been previously added
 to receive rerouting notifications.
| Parameters | |
|---|---|
listener | 
        
          AudioRouting.OnRoutingChangedListener: The previously added AudioRouting.OnRoutingChangedListener interface
 to remove. | 
      
setPreferredDevice
public abstract boolean setPreferredDevice (AudioDeviceInfo deviceInfo)
Specifies an audio device (via an AudioDeviceInfo object) to route
 the output/input to/from.
| Parameters | |
|---|---|
deviceInfo | 
        
          AudioDeviceInfo: The AudioDeviceInfo specifying the audio sink or source.
  If deviceInfo is null, default routing is restored. | 
      
| Returns | |
|---|---|
boolean | 
        true if succesful, false if the specified AudioDeviceInfo is non-null and
 does not correspond to a valid audio device. | 
      
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-03-13 UTC.