Advertisement
egasimus

Untitled

Sep 30th, 2014
191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE OverloadedStrings #-}
  2.  
  3. import Data.Maybe
  4. import DBus
  5. import DBus.Client
  6. import DBus.Socket
  7.  
  8. main = do
  9.     sessionBus <- connectSession
  10.     socketPath <- getPulseAddress sessionBus
  11.     case socketPath of
  12.         Nothing -> putStrLn "FAIL can't find pulseaudio socket."
  13.         Just s  -> do
  14.             putStr $ "...  connecting to pulseaudio at: " ++ s
  15.             pulseBus <- pulseConnect socketPath
  16.             putStrLn $ "\rOK  "
  17.  
  18.  
  19. getPulseAddress :: Client -> IO (Maybe String)
  20. getPulseAddress client = do
  21.     reply <- call_ client (methodCall "/org/pulseaudio/server_lookup1"
  22.                              "org.freedesktop.DBus.Properties"
  23.                              "Get")
  24.         { methodCallDestination = Just "org.PulseAudio1"
  25.         , methodCallBody        = [toVariant ("org.PulseAudio.ServerLookup1" :: String),
  26.                                    toVariant ("Address" :: String)]}
  27.     return $ (fromVariant =<< fromVariant ((methodReturnBody reply) !! 0))
  28.  
  29.  
  30. pulseConnect :: Maybe String -> Maybe (IO Socket)
  31. pulseConnect Nothing  = Nothing
  32. pulseConnect (Just s) = maybe Nothing (Just . open) $ parseAddress s
Advertisement
RAW Paste Data Copied
Advertisement