How can I play an mp3 file?

How can I write a script in ruby ​​that plays an mp3 file (background music) when executed from the command line?

I tried this

run = "mplayer #{"/Users/bhushan/resume/m.mp3"} -ao sdl -vo x11 -framedrop -cache 16384 -cache-min 20/100"
system(run)

but it doesn’t work either, above is a specific player. what if the user does not have mplayer installed. Is there a better way?

+5
source share
4 answers

I usually just do

pid = fork{ exec 'mpg123','-q', file }
+14
source

Try it this way: it uses Shoes for magic, everything you need, I hope http://rubylearning.com/blog/2008/05/31/a-teeny-weeny-mp3-player-using-ruby-and-shoes /

#my_mp3player01.rb
Shoes.app do
  button( 'play' ){ @v.play }
  button( 'pause' ){ @v.pause }
  button( 'stop' ){ @v.stop }
  @v = video "C:/rubyprograms/mp3player/ruby.mp3"
end
+7
source

ruby, .

, , :

https://gist.github.com/2217498

mplayer sox vlc - .

. hardcoded mplayer yaml, .

gstreamer ruby-gtk.

But remember that Ruby alone cannot play audio files.

It would be great if someone could create a pure ruby ​​player.

+1
source
+1
source

All Articles