34 lines
812 B
Haskell
34 lines
812 B
Haskell
|
module Main where
|
||
|
|
||
|
import Control.Concurrent ( threadDelay )
|
||
|
import Control.Monad ( forever )
|
||
|
import Control.Monad.IO.Class ( MonadIO(liftIO) )
|
||
|
import DBus.Mpris
|
||
|
( current,
|
||
|
PlaybackStatus,
|
||
|
Config(playbackStatusHook),
|
||
|
liftMpris,
|
||
|
mpris,
|
||
|
def,
|
||
|
Callback,
|
||
|
getPlayer,
|
||
|
Player(Player) )
|
||
|
|
||
|
mpdPlaybackStatusHook :: Callback PlaybackStatus
|
||
|
mpdPlaybackStatusHook = do
|
||
|
player <- liftMpris current
|
||
|
case player of
|
||
|
Nothing -> liftIO . print $ "Failed to retrieve DBus"
|
||
|
(Just busName) -> do
|
||
|
(Player _ _ _ _ m) <- liftMpris $ getPlayer busName
|
||
|
liftIO . putStrLn $ "Status changed " ++ show m
|
||
|
|
||
|
config :: Config
|
||
|
config =
|
||
|
def
|
||
|
{ playbackStatusHook = mpdPlaybackStatusHook
|
||
|
}
|
||
|
|
||
|
main :: IO ()
|
||
|
main = mpris config (liftIO $ forever $ threadDelay 800000)
|