Skip to content

Instantly share code, notes, and snippets.

@Heinrich-XIAO
Created February 6, 2024 12:55
Show Gist options
  • Save Heinrich-XIAO/4ad7b92dda62661d62fd3eb4d7624237 to your computer and use it in GitHub Desktop.
Save Heinrich-XIAO/4ad7b92dda62661d62fd3eb4d7624237 to your computer and use it in GitHub Desktop.
Music Player
import System.Process
import Control.Concurrent
import System.Directory
import System.FilePath ((</>))
printFiles :: [String] -> IO()
printFiles (x:xs) = do
putStrLn x
printFiles xs
main :: IO ()
main = do
let songsDir = "./songs"
files <- getDirectoryContents songsDir
let validFiles = filter (\f -> f /= "." && f /= "..") files
-- Start the background pro -- Print the list of valid files
putStrLn "All Songs:"
mapM_ putStrLn validFiles
chosenSongIndex <- getLine
let chosenSong = validFiles !! (read chosenSongIndex :: Int)
callCommand $ "mpg123 " ++ "\"./songs/" ++ chosenSong ++ "\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment