packages feed

XMMS-0.1: example/tut4.hs

import System
import Prelude hiding (init)
import qualified Network.XMMS.Playlist as Playlist
import Network.XMMS.Playback
import Network.XMMS.Medialib
import Network.XMMS.Client
import Control.Monad
import Data.Maybe
import Data.Map (Map)
import qualified Data.Map as Map

    
printInfo connection id = do
    result <- medialibGetInfo connection id
    resultWait result
    infoOnId <- resultGetValue result
    case infoOnId of
        XMMSDict dict -> do
            let info = propdictToDict dict
                artist = liftM xmmsString $ Map.lookup "artist" info
                title = liftM xmmsString $ Map.lookup "title" info
                bitrate = liftM (show.xmmsInt) $ Map.lookup "bitrate" info
                
            when (isJust artist) (putStrLn $ "artist = " ++ fromJust artist)
            when (isJust title) (putStrLn $ "title = " ++ fromJust title)
            when (isJust bitrate) (putStrLn $ "bitrate = " ++ fromJust bitrate)
            
        _ -> error "not a dictionary"

main = do

    connection <- init "tutorial4"
    xmmsPath <- catch (getEnv "XMMS_PATH")
                      (\e -> return "")
    connectRes <- connect connection xmmsPath
    if connectRes == 0 then do
        errorMsg <- getLastError connection
        putStrLn $ "Connection failed: " ++ errorMsg
     else do
        result <- Playlist.listEntries connection ""
        resultWait result
        returnValue <- resultGetValue result
        case returnValue of
            XMMSError msg -> putStrLn $ "Couldn't retrieve playlist entries: " ++ msg
            XMMSList ids -> mapM_ (\(XMMSInt id) -> printInfo connection id) ids
            _ -> return ()