[Linux] Activate AirPods as output device when connecting

This commit is contained in:
Tim Gromeyer
2025-04-18 17:28:37 +02:00
committed by Tim Gromeyer
parent f75419748b
commit c2db0afdf1
2 changed files with 16 additions and 1 deletions

View File

@@ -320,6 +320,7 @@ private slots:
// Clear the device name and model
m_deviceName.clear();
connectedDeviceMacAddress.clear();
mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress);
m_model = AirPodsModel::Unknown;
emit deviceNameChanged(m_deviceName);
emit modelChanged();
@@ -500,7 +501,6 @@ private slots:
localSocket->connectToService(device.address(), QBluetoothUuid("74ec2172-0bad-4d01-8f77-997b2be0722a"));
connectedDeviceMacAddress = device.address().toString().replace(":", "_");
mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress);
notifyAndroidDevice();
}
@@ -600,6 +600,11 @@ private slots:
{
parseMetadata(data);
initiateMagicPairing();
mediaController->setConnectedDeviceMacAddress(connectedDeviceMacAddress);
if (isLeftPodInEar() || isRightPodInEar()) // AirPods get added as output device only after this
{
mediaController->activateA2dpProfile();
}
emit airPodsStatusChanged();
}
else

View File

@@ -145,6 +145,11 @@ void MediaController::handleConversationalAwareness(const QByteArray &data) {
}
void MediaController::activateA2dpProfile() {
if (connectedDeviceMacAddress.isEmpty()) {
LOG_WARN("Connected device MAC address is empty, cannot activate A2DP profile");
return;
}
LOG_INFO("Activating A2DP profile for AirPods");
int result = QProcess::execute(
"pactl", QStringList()
@@ -156,6 +161,11 @@ void MediaController::activateA2dpProfile() {
}
void MediaController::removeAudioOutputDevice() {
if (connectedDeviceMacAddress.isEmpty()) {
LOG_WARN("Connected device MAC address is empty, cannot remove audio output device");
return;
}
LOG_INFO("Removing AirPods as audio output device");
int result = QProcess::execute(
"pactl", QStringList()