Setting the audio output mode

Using the AudioOutputControl extension, MIDlets can override the default audio routing on the device and control which audio output is used to play back audio. MIDlets can thus use AudioOutputControl to define their own default routing for audio. Audio can be routed to the device loudspeaker or any audio peripheral connected to the device. The routing is based on audio output modes, each of which is associated with a particular set of audio output devices. For example, the PUBLIC mode is associated with the device loudspeaker and wireless speakers. MIDlets can also query the currently used audio output mode.

On Symbian devices, each Player instance controls its audio routing independently. When a Player changes the routing, the change affects only that Player. Other Players in the same MIDlet or other MIDlets are unaffected.

On Series 40 devices, AudioOutputControl is a global control. Setting the routing from one MIDlet affects all MIDlets. MIDlets that change the audio routing must set it back to the default before exiting. Moreover, since the control is global and can therefore compromise device security, only MIDlets that run in the manufacturer or operator domain can use AudioOutputControl.

To set the audio output mode in your MIDlet:

  1. Import the AudioOutputControl class:

    import com.nokia.mid.media.AudioOutputControl;
  2. For controlling the audio output, create an AudioOutputControl object:

    • On a Series 40 device:

      AudioOutputControl audioOutputControl = (AudioOutputControl)GlobalManager.getControl("com.nokia.mid.media.AudioOutputControl");
    • On a Symbian device:

      AudioOutputControl audioOutputControl = (AudioOutputControl)player.getControl("com.nokia.mid.media.AudioOutputControl");

      In the above code snippet, player is an object instance of Player.

  3. Set the audio output mode by using the setOutputMode method:

    audioOutputControl.setOutputMode(mode);

    The mode parameter identifies which audio output mode to use, that is, where to route audio playback. Use one of the following modes:

    Note: The modes are defined as integer constants in the API. The Mode column indicates the constant name, while the Value column shows the integer value for the constant. Use either the constant or the integer to set the mode.

    Table: Supported audio output modes

    Mode

    Description

    Value

    Example

    DEFAULT

    Audio routing is set to the device default.

    By default, audio is routed to the device loudspeaker. If a headset is connected to the device, audio is automatically routed to it. If the headset is disconnected, audio is routed back to the loudspeaker.

    0

    setOutputMode(DEFAULT)

    setOutputMode(0)

    ALL

    Audio is routed to one public and one private output at the same time.

    The primary output within the available public and private outputs is selected by the device and can change dynamically when audio peripherals are connected or disconnected by the user. For more information about output priority, see modes PRIVATE and PUBLIC.

    Note: This mode is not supported on Series 40 devices.

    1

    setOutputMode(ALL)

    setOutputMode(1)

    NONE

    Audio is not routed to any output.

    Note: This mode is not supported on Series 40 devices.

    2

    setOutputMode(NONE)

    setOutputMode(2)

    PRIVATE

    Audio is routed to a private audio output, if available. This can be a wired or wireless headset or the device earpiece.

    If there are multiple private outputs available on the device, audio is routed to only one of them according to the following priority:

    1. Wired headset

    2. Wireless headset (when activated by the user or UI)

    3. Device earpiece

    3

    setOutputMode(PRIVATE)

    setOutputMode(3)

    PUBLIC

    Audio is routed to a public audio output. This can be the device loudspeaker or wireless speakers.

    If there are multiple public outputs available on the device, audio is routed to only one of them according to the following priority:

    1. Wireless speakers (when activated by the user or UI)

    2. Device loudspeaker

    Note: On Series 40 devices, if a wired or wireless headset is connected to the device, audio cannot be routed to the device loudspeaker via AudioOutputControl.

    4

    setOutputMode(PUBLIC)

    setOutputMode(4)

  4. If the MIDlet is running on a Series 40 device, set the audio output mode to DEFAULT after the MIDlet is finished playing audio:

    audioOutputControl.setOutputMode(DEFAULT);

To download an example MIDlet that shows you how to use AudioOutputControl to manage audio output modes, see section Example: AudioOutputControl MIDlet.