Forum: Ruby how to use ruby run a mp3 file?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhenning G. (Guest)
on 2007-07-29 12:16
I want to use ruby run excute mp3 file,but I don't know how to get it
work。
I have a song on D drive and I write a callme.rb
++++++++++
def callme
 system("2k7.mp3" )
end
callme
+++++++++

I am run "ruby callme.rb" in "CMD"
but didn't run the 2k7.mp3  song
why? how shoud I do it right?


my system is windows XP
Chris L. (Guest)
on 2007-07-29 16:21
I haven't got a windows system to test this on, but does this work ?

 def callme
  system("open 2k7.mp3" )
 end

 callme


Chris
Brett S. (Guest)
on 2007-07-30 00:40
(Received via mailing list)
Almost, on Windows the command is "start":

def callme
  system("start 2k7.mp3")
end

callme

That should launch your system's default mp3 player.  I think that will
only work on the native windows build of ruby, not cygwin.
Robby R. (Guest)
on 2007-07-30 02:49
(Received via mailing list)
Zhenning G. wrote:
> I am run "ruby callme.rb" in "CMD"
> but didn't run the 2k7.mp3  song
> why? how shoud I do it right?
>
>
> my system is windows XP

The Rails plugin, ActsAsHasselhoff[1], provided a way to do this from
within Ruby on Rails. Might  be worth looking over the code[2]. ;-)

[1] http://interblah.net/2006/10/4/ajaxworld-presentation
[2] http://rubyurl.com/yrf

Good luck!

Robby
Zhenning G. (Guest)
on 2007-07-30 06:10
you guy far too kind!
==
system("start XX.mp3")
===

that's ok!
Adam A. (Guest)
on 2008-02-17 18:01
Hi im having a problem playing a song. Im basically got this is my file

system( "start G:\Itunes_To be imported\02 - Anne Clark - The Power
Game.mp3")

and then running it from within Radrails.

Its keeps complaining "Windows cannot find the file 'G:\Itunes'....."

What am i doing wrong? (The song definately is in that path as i copied
its path from its properties)
Tim H. (Guest)
on 2008-02-17 20:03
(Received via mailing list)
Adam A. wrote:
> its path from its properties)
>
>
>
Do you need to escape those backslashes?

G:\\Itunes etc.
(Guest)
on 2008-02-18 08:25
(Received via mailing list)
On Feb 17, 10:02 am, Tim H. <removed_email_address@domain.invalid> wrote:
>
> --
> RMagick:http://rmagick.rubyforge.org/
> RMagick 2:http://rmagick.rubyforge.org/rmagick2.html

Or  just use single quotes (or %q{start G:\blah.mp3}) rather than
double quotes if you don't need to interpolate the string.  That will
make it easier to read than the extra \'s.

irb(main):001:0> %q{start G:\blah.mp3}
=> "start G:\\blah.mp3"
Adam A. (Guest)
on 2008-02-18 15:31
ahh yeah i forgot about escaping the backslashes. Ill try both of your
solutions later tonight. thanks very much.
Jano S. (Guest)
on 2008-02-18 16:20
(Received via mailing list)
On Feb 17, 2008 5:01 PM, Adam A. <removed_email_address@domain.invalid> wrote:
> its path from its properties)
I guess you need to quote the file name, i.e.

system( "start \"G:\\Itunes_To be imported\\02 - Anne Clark - The
Power Game.mp3\"")

otherwise the start command considers only the first "word" as the
command to execute,
and the rest are parameters to that command.

Note: due to ****** (censored) design of the start command, any time
you need to quote the command,
you have to add "" in front of it, otherwise the command ends as the
window title. So the final version is:

system( "start \"\" \"G:\\Itunes_To be imported\\02 - Anne Clark - The
Power Game.mp3\"")

Jano
fedzor (Guest)
on 2008-02-20 22:53
(Received via mailing list)
Anyone know much about ruby-audiere?

Maybe it's time someone write something like that for multiple OSes.
could probably be easy to do in Rubinius...

ari
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.
This topic is locked and can not be replied to.