Monitoring for changes in the audio routing

On Symbian devices, MIDlets can use PlayerListener to monitor for changes in the audio routing. Whenever the routing is changed, either by AudioOutputControl or when an audio peripheral is connected or disconnected by the user, the MIDlet receives an event notification from PlayerListener.playerUpdate. The event name is com.nokia.audiooutputchange.event and the event data is of type AudioOutput.

To monitor for changes in the audio routing:

  1. Import the AudioOutput class:

    import com.nokia.mid.media.AudioOutput;
    
  2. Set your MIDlet to implement PlayerListener:

    public class MyMIDlet extends MIDlet implements PlayerListener {
    
        // implement other necessary classes in the above declaration
        // define the MIDlet functionality, including steps 3 and 4
    
    }
  3. Add a PlayerListener for your Player instance by using the addPlayerListener method:

    player.addPlayerListener(this);
  4. Implement the playerUpdate method for handling any com.nokia.audiooutputchange.event events from the Player:

    public void playerUpdate(Player player, String event, Object eventData)
    {
        if (event.equals("com.nokia.audiooutputchange.event"))
        {
            // process the event
            // tip: to retrieve the newly active mode, use: (AudioOutput)eventData.getActiveOutputMode()
        }
    }

To download an example MIDlet that shows you how to use AudioOutputControl to receive notifications when the audio output mode changes, see section Example: AudioOutputControl MIDlet.