Audio Management
PUBLISHED
You can control the audio behavior of your application.
The main features of the Tizen.Multimedia.AudioManager
class include:
- Controlling the volume
You can control the output volume by managing the audio type and its volume level.
- Querying audio devices
You can retrieve various device information, such as the device state.
Prerequisites
To control volume levels, the application has to request permission by adding the following privilege to the tizen-manifest.xml
file:
<privileges> <privilege>http://tizen.org/privilege/volume.set</privilege> </privileges>
Controlling Volume Levels
You can manage the volume level of a specific audio type. You can set and get a volume level and a maximum volume level of a particular audio type.
Normally, if there is an active output stream, the VolumeController.CurrentPlaybackType
property of the Tizen.Multimedia.AudioManager [1] class returns the stream audio type, and if not, it returns AudioVolumeType.None
.
To control the volume of your application:
- To receive a notification whenever the volume changes, define and register an event handler for the
VolumeController.Changed
event of theTizen.Multimedia.AudioManager
class:void OnVolumeChanged(object sender, VolumeChangedEventArgs args) { Tizen.Log.Info("AudioManager", $"{args.Type} volume changed to {args.Level}"); } AudioManager.VolumeController.Changed += OnVolumeChanged;
When the volume changes, the event handler provides in its parameters the audio type that has changed and the new volume level.
- To retrieve the current and maximum volumes for a specific audio type, use the
VolumeController.Level
andVolumeController.MaxLevel
properties of theTizen.Multimedia.AudioManager
class:
var type = AudioVolumeType.Media; var curVol = AudioManager.VolumeController.Level[type]; var maxVol = AudioManager.VolumeController.MaxLevel[type];
- To set the volume level, use the
VolumeController.Level
property.In the following example, a value is received from application UI slider, with which the user sets the volume level.
var type = AudioVolumeType.Media; int value; /// Make sure the value is within the system maximum volume /// by checking the VolumeController.MaxLevel property AudioManager.VolumeController.Level[type] = value;
Querying Audio Devices
The audio behavior of your application must change depending on the audio devices that are connected.
To query audio device information:
- To access device information:
- Retrieve the list of the currently connected audio devices with the
GetConnectedDevices()
method of the Tizen.Multimedia.AudioManager [1] class:IEnumerable<AudioDevice> connectedDevices = AudioManager.GetConnectedDevices();
- Retrieve the device information from the Tizen.Multimedia.AudioDevice [2] class, which has the following properties:
Type
: Device typeIoDirection
: Device IO directionId
: Device IDName
: Device nameIsRunning
: Device running state
- Retrieve the list of the currently connected audio devices with the
- To get a notification when the audio device connection or state changes, add event handlers for the
DeviceConnectionChanged
andDeviceRunningChanged
events of theTizen.Multimedia.AudioManager
class:- To receive a notification whenever the device connection state changes:
void OnDeviceConnectionChanged(object sender, AudioDeviceConnectionChangedEventArgs args) { if (args.IsConnected) { if (args.Device.Type == AudioDeviceType.BluetoothMedia) /// Connected device type is Bluetooth, handle accordingly else /// Handle accordingly } else { if (args.Device.Type == AudioDeviceType.BluetoothMedia) /// Disconnected device type is Bluetooth, handle accordingly else /// Handle accordingly } } AudioManager.DeviceConnectionChanged += OnDeviceConnectionChanged;
- To receive a notification whenever the device state changes:
void OnDeviceRunningChanged(object sender, AudioDeviceRunningChangedEventArgs args) { if (args.Device.Type == AudioDeviceType.BluetoothMedia) { if (args.Device.IsRunning == false) /// Bluetooth device is not running, handle accordingly else /// Handle accordingly } else { /// Handle accordingly } } AudioManager.DeviceRunningChanged += OnDeviceRunningChanged;
Note The initial running state of the connected device isfalse
, which means the connected device is not running.
- To receive a notification whenever the device connection state changes: