Command line mp3 player in Linux
This post is after about a month long hibernation from my blog.I made my mind up to listen songs as i usually do (it contributes to my hobby). In fact, i was suffering with a headburst headache, so i thought songs might be the stress buster and good entertainer too. What striked my mind was why couldn’t i play the tracks on command line rather playing’em in traditional RhythmBox or Amarok etc. The way i thought, the way i found…some googling let me find such a tool named mpg123, which is nothing but a command line player cum MPEG streamer.
Installation on Ubuntu/Debian: sudo apt-get install mpg123
Installation on RedHat/Fedora/Cent OS: For this, we have to first enable the rpmforge repo and try
yum install mpg123
and you are done.
Code
class Arraydef shuffle() sort_by { rand }end def shuffle!() replace(shuffle)enddef random_element() shuffleendend class ShufflePlayerdef initialize(files) puts files @files = filesend def play() puts "play()" @files.shuffle.each do |file| puts file play_file(file) endendprivatedef play_file(file) puts "play_file(file)" system("mpg123 #{file}")endend songs = [] Dir.foreach(".") do |entry| if(entry[-4..-1].eql?(".mp3") ) puts entry songs << Dir.pwd + "/" +entry end endsp = ShufflePlayer.new(ARGV || songs)sp.play()
页:
[1]