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 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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值