mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-01 15:49:10 +00:00
[Linux] Pause music when airpods disconnect
This commit is contained in:
@@ -359,13 +359,15 @@ private slots:
|
||||
LOG_WARN("Socket is still open, closing it");
|
||||
socket->close();
|
||||
socket = nullptr;
|
||||
discoveryAgent->start();
|
||||
}
|
||||
if (phoneSocket && phoneSocket->isOpen())
|
||||
{
|
||||
phoneSocket->write(AirPodsPackets::Connection::AIRPODS_DISCONNECTED);
|
||||
LOG_DEBUG("AIRPODS_DISCONNECTED packet written: " << AirPodsPackets::Connection::AIRPODS_DISCONNECTED.toHex());
|
||||
}
|
||||
|
||||
mediaController->pause();
|
||||
discoveryAgent->start();
|
||||
}
|
||||
void bluezDeviceDisconnected(const QString &address)
|
||||
{
|
||||
|
||||
@@ -73,14 +73,7 @@ void MediaController::handleEarDetection(const QString &status) {
|
||||
QString playbackStatus = process.readAllStandardOutput().trimmed();
|
||||
LOG_DEBUG("Playback status: " << playbackStatus);
|
||||
if (playbackStatus == "Playing") {
|
||||
int result = QProcess::execute("playerctl", QStringList() << "pause");
|
||||
LOG_DEBUG("Executed 'playerctl pause' with result: " << result);
|
||||
if (result == 0) {
|
||||
LOG_INFO("Paused playback via Playerctl");
|
||||
wasPausedByApp = true;
|
||||
} else {
|
||||
LOG_ERROR("Failed to pause playback via Playerctl");
|
||||
}
|
||||
pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,6 +176,20 @@ MediaController::MediaState MediaController::mediaStateFromPlayerctlOutput(
|
||||
}
|
||||
}
|
||||
|
||||
void MediaController::pause() {
|
||||
int result = QProcess::execute("playerctl", QStringList() << "pause");
|
||||
LOG_DEBUG("Executed 'playerctl pause' with result: " << result);
|
||||
if (result == 0)
|
||||
{
|
||||
LOG_INFO("Paused playback via Playerctl");
|
||||
wasPausedByApp = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed to pause playback via Playerctl");
|
||||
}
|
||||
}
|
||||
|
||||
MediaController::~MediaController() {
|
||||
if (playerctlProcess) {
|
||||
playerctlProcess->terminate();
|
||||
|
||||
@@ -23,6 +23,8 @@ public:
|
||||
void removeAudioOutputDevice();
|
||||
void setConnectedDeviceMacAddress(const QString &macAddress);
|
||||
|
||||
void pause();
|
||||
|
||||
Q_SIGNALS:
|
||||
void mediaStateChanged(MediaState state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user