Created
February 6, 2024 12:55
-
-
Save Heinrich-XIAO/4ad7b92dda62661d62fd3eb4d7624237 to your computer and use it in GitHub Desktop.
Music Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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