Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions linux/media/mediacontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ void MediaController::handleEarDetection(EarDetection *earDetection)
shouldResume = primaryInEar || secondaryInEar;
}

if (shouldPause && isActiveOutputDeviceAirPods())
// Pause if conditions are met (removed isActiveOutputDeviceAirPods check as it
// fails on some systems where PulseAudio can't detect the Bluetooth card)
if (shouldPause)
{
if (getCurrentMediaState() == Playing)
{
LOG_DEBUG("Pausing playback for ear detection");
pause();
}
LOG_INFO("Ear detection triggered pause");
pause();
}

// Then handle device profile switching
Expand All @@ -65,8 +64,9 @@ void MediaController::handleEarDetection(EarDetection *earDetection)
activateA2dpProfile();

// Resume if conditions are met and we previously paused
if (shouldResume && !pausedByAppServices.isEmpty() && isActiveOutputDeviceAirPods())
if (shouldResume && !pausedByAppServices.isEmpty())
{
LOG_INFO("Ear detection triggered resume");
play();
}
}
Expand Down Expand Up @@ -307,6 +307,24 @@ void MediaController::play()
return;
}

// If we paused via playerctl fallback, resume via playerctl
if (pausedByAppServices.contains("playerctl"))
{
LOG_INFO("Resuming media via playerctl");
int result = QProcess::execute("playerctl", QStringList() << "play");
if (result == 0)
{
LOG_INFO("Resumed media via playerctl");
pausedByAppServices.clear();
}
else
{
LOG_WARN("playerctl play returned: " << result);
}
return;
}

// Try to resume via DBus
QDBusConnection bus = QDBusConnection::sessionBus();
int resumedCount = 0;

Expand Down Expand Up @@ -400,7 +418,18 @@ void MediaController::pause()
}
else
{
LOG_INFO("No playing media players found to pause");
// Fallback to playerctl if DBus didn't find any playing media
LOG_INFO("No playing media found via DBus, trying playerctl fallback");
int result = QProcess::execute("playerctl", QStringList() << "pause");
if (result == 0)
{
LOG_INFO("Paused media via playerctl fallback");
pausedByAppServices << "playerctl";
}
else
{
LOG_DEBUG("playerctl fallback returned: " << result);
}
}
}

Expand Down