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:
Import the AudioOutputControl
class:
import com.nokia.mid.media.AudioOutputControl;
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
.
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.
Mode |
Description |
Value |
Example |
---|---|---|---|
|
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. |
|
|
|
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 Note: This mode is not supported on Series 40 devices. |
|
|
|
Audio is not routed to any output. Note: This mode is not supported on Series 40 devices. |
|
|
|
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: |
|
|
|
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: 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 |
|
|
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.