simple-awesome/media_control.lua

54 lines
1.2 KiB
Lua

-- Control playing music/media and sound volume
-- Currently supports :
-- - playerctl
-- - Spotify
-- DEBUG
local inspect = require("debug/inspect")
local awful = require("awful")
local naughty = require("naughty")
local hasPlayerctl = os.execute("playerctl -v") == true
-- playerctl
function sendToPlayerctl(command)
os.execute("playerctl " .. command)
end
-- Spotify
function sendToSpotify(command)
awful.util.spawn_with_shell("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." .. command)
end
-- {{{ Control
local playPause = function()
if hasPlayerctl then
sendToPlayerctl("play-pause")
else
sendToSpotify("PlayPause")
end
end
local nextTrack = function()
if hasPlayerctl then
sendToPlayerctl("next")
else
sendToSpotify("Next")
end
end
local previousTrack = function()
if hasPlayerctl then
sendToPlayerctl("previous")
else
sendToSpotify("Previous")
end
end
-- }}}
return {
playPause = playPause,
nextTrack = nextTrack,
previousTrack = previousTrack
}