Audio Management

You can control the audio behavior of your application.

The main features of the Tizen.Multimedia.AudioManager class include:

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 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 the Tizen.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 and VolumeController.MaxLevel properties of the Tizen.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:

    1. Retrieve the list of the currently connected audio devices with the GetConnectedDevices() method of the Tizen.Multimedia.AudioManager class:

      IEnumerable<AudioDevice> connectedDevices = AudioManager.GetConnectedDevices();
      
    2. Retrieve the device information from the Tizen.Multimedia.AudioDevice class, which has the following properties:
      • Type: Device type
      • IoDirection: Device IO direction
      • Id: Device ID
      • Name: Device name
      • IsRunning: Device running state
  • To get a notification when the audio device connection or state changes, add event handlers for the DeviceConnectionChanged and DeviceRunningChanged events of the Tizen.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 is false, which means the connected device is not running.