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
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 Array
def shuffle()
sort_by { rand }
end
def shuffle!()
replace(shuffle)
end
def random_element()
shuffle[0]
end
end
class ShufflePlayer
def initialize(files)
puts files
@files = files
end
def play()
puts "play()"
@files.shuffle.each do |file|
puts file
play_file(file)
end
end
private
def play_file(file)
puts "play_file(file)"
system("mpg123 #{file}")
end
end
songs = []
Dir.foreach(".") do |entry|
if(entry[-4..-1].eql?(".mp3") )
puts entry
songs << Dir.pwd + "/" +entry
end
end
sp = ShufflePlayer.new(ARGV[0] || songs)
sp.play()