packages feed

XMMS-0.1: example/tut7.hs

import System
import Data.IORef
import Prelude hiding (init)
import Network.XMMS.Playback
import Network.XMMS.Client
import Network.XMMS.Client.Glib
import Network.XMMS.Playlist as Playlist
import System.Glib.MainLoop

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
        loop <- mainLoopNew Nothing False
        result <- broadcastCurrentID connection
        count <- newIORef 0
        resultNotifierSet 
            result 
            (\(XMMSInt pos) -> do
                putStrLn $ "playing ID: " ++ (show pos)
                modifyIORef count (+1)
                countV <- readIORef count
                if countV<5 then do
                    return True
                 else do 
                    putStrLn $ "Playback has been called " ++ (show countV) ++ " times. Exiting..."
                    mainLoopQuit loop
                    return False)
        mainLoopGmainInit connection
        mainLoopRun loop