C

Audio Zone Controller

Implements an Audio Routing Controller to demonstrate Qt Audio Manager.

"Main view of installed applications"

Building and deploying the example

See specific steps relating to building and deploying Qt for Android Automotive examples.

Overview

This example demonstrates the Qt Android Apps Utils and Qt Audio Manager modules to manipulate and read the audio zones of specific apps by using the app UID.

When starting the app, a list of all installed apps, excluding system apps, will be displayed in a GridLayout. Each list element has the icon, package name, app name, UID, and audio zone of the app. Pressing on an item will display a popup menu which allows manipulation of the audio zone for that app.

Including the API

To use dynamic audio routing based on UID, we first need to import the Qt Audio Manager and Apps Utils modules:

import QtAndroidAutomotive.AndroidAudioManager
import QtAndroidAutomotive.QtAndroidAppsUtils

Reading audio zones

In order to list available audio zones on the device, the DynamicAudioRouting::audioZones property from DynamicAudioRouting class can be used:

        Instantiator {
            model: DynamicAudioRouting.audioZones
            delegate: MenuItem {
                text: modelData
                onTriggered: {
                    const success = DynamicAudioRouting.setZoneIdForUid(modelData,
                                                                        audioZoneMenu.currentUid)
                    if (success)
                        window.audioZoneModified(audioZoneMenu.currentUid)
                }
            }

            onObjectAdded: (index, object) => audioZoneMenu.insertItem(index, object)
        }

Manipulating audio zones

Clearing the audio zone of a specific app

In order to clear the current audio zone from an app, the DynamicAudioRouting::clearZoneIdForUid function from DynamicAudioRouting can be used:

            onTriggered: {
                const success = DynamicAudioRouting.clearZoneIdForUid(contextMenu.currentUid)
                if (success)
                    window.audioZoneModified(contextMenu.currentUid)
            }
Setting the audio zone for a specific app

In order to set an app to use a specific audio zone, we can use the DynamicAudioRouting::setZoneIdForUid function:

                onTriggered: {
                    const success = DynamicAudioRouting.setZoneIdForUid(modelData,
                                                                        audioZoneMenu.currentUid)
                    if (success)
                        window.audioZoneModified(audioZoneMenu.currentUid)
                }

Available under certain Qt licenses.
Find out more.