[Linux] Pause music when airpods disconnect

This commit is contained in:
Tim Gromeyer
2025-04-15 19:37:39 +02:00
parent e384840bcc
commit ecab6a9858
3 changed files with 20 additions and 9 deletions

View File

@@ -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();