Playing music with ruby

hello all, I have a quick question. I know ruby has no native sound support
and at least from what I've read if you want music in your app you have to
do something along the lines of a system call opening the file up in
mplayer or mpg123 from within the app. my question is, what would be good
lightweight easily re distributable player to embed in my app? I guess i
should also mention the purpose of the app. I'm just trying to create a
simple mp3 player with basic controls (back forward play pause etc).
eventually once I got the basics working, I want to add support for lyrics
search and stuff like that (that's my main goal but i need basic controls
first)

Why not just system call the music and thread it so that it'll play while the program runs on a superset thread? This could potentially cause problems when one thread crashes

- Thomas Perkins

···

On Nov 19, 2016, at 3:23 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

hello all, I have a quick question. I know ruby has no native sound support and at least from what I've read if you want music in your app you have to do something along the lines of a system call opening the file up in mplayer or mpg123 from within the app. my question is, what would be good lightweight easily re distributable player to embed in my app? I guess i should also mention the purpose of the app. I'm just trying to create a simple mp3 player with basic controls (back forward play pause etc). eventually once I got the basics working, I want to add support for lyrics search and stuff like that (that's my main goal but i need basic controls first)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

you mean instead of:
  %x(mpg123 -q file.mp3) just call the file like: %(file.mp3)? will that
work? and if so what would it use to play the file, just the system
default? and wouldnt that open a new window if that default app is
something like windows media player or rythmbox (any gui player)? maybe I'm
not totally understanding you. also what is a superset thread? currently my
code to initially open the song is something like this:
  def open_song(file)
    fork do
      %x(mpg123 -q file.mp3)
    end
  end

but I'm still working on a way to be able to pause or stop...

···

On Sat, Nov 19, 2016 at 1:27 PM, thomas Perkins <thomas.perkins23@icloud.com > wrote:

Why not just system call the music and thread it so that it'll play while
the program runs on a superset thread? This could potentially cause
problems when one thread crashes

- Thomas Perkins

> On Nov 19, 2016, at 3:23 PM, Micky Scandal <mickyscandal@gmail.com> > wrote:
>
> hello all, I have a quick question. I know ruby has no native sound
support and at least from what I've read if you want music in your app you
have to do something along the lines of a system call opening the file up
in mplayer or mpg123 from within the app. my question is, what would be
good lightweight easily re distributable player to embed in my app? I guess
i should also mention the purpose of the app. I'm just trying to create a
simple mp3 player with basic controls (back forward play pause etc).
eventually once I got the basics working, I want to add support for lyrics
search and stuff like that (that's my main goal but i need basic controls
first)
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=
>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Perhaps Ruby and SDL rather than an external application

That's actually what I've been trying to do. But honestly I think sdl is a
little Beyond me. I posted up a few different questions seeing if anybody
knows where some good tutorials or examples are because with just the stock
documentation I'm lost

···

On Nov 19, 2016 1:45 PM, "Peter Hickman" <peterhickman386@googlemail.com> wrote:

Perhaps Ruby and SDL rather than an external application

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Now you got me a little bit confused... Isn't shoes just a GUI tool kit?

···

On Nov 19, 2016 1:55 PM, "thomas Perkins" <thomas.perkins23@icloud.com> wrote:

Why not use shoes

- Thomas Perkins

On Nov 19, 2016, at 3:50 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

That's actually what I've been trying to do. But honestly I think sdl is a
little Beyond me. I posted up a few different questions seeing if anybody
knows where some good tutorials or examples are because with just the stock
documentation I'm lost

On Nov 19, 2016 1:45 PM, "Peter Hickman" <peterhickman386@googlemail.com> > wrote:

Perhaps Ruby and SDL rather than an external application

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe
<ruby-talk-request@ruby-lang.org?subject=unsubscribe>>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Why not use shoes

- Thomas Perkins

···

On Nov 19, 2016, at 3:50 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

That's actually what I've been trying to do. But honestly I think sdl is a little Beyond me. I posted up a few different questions seeing if anybody knows where some good tutorials or examples are because with just the stock documentation I'm lost

On Nov 19, 2016 1:45 PM, "Peter Hickman" <peterhickman386@googlemail.com> wrote:
Perhaps Ruby and SDL rather than an external application

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Here's a couple ways to do it:

process = fork{ exec "mp3", "-q", file }

Shoes.app do
  button("play"){ @v.play }
  button("stop"){ @v.stop }
  button("pause"){ @v.pause }
  @v = "some/mp3/file"
end

- Thomas Perkins

···

On Nov 19, 2016, at 3:54 PM, thomas Perkins <thomas.perkins23@icloud.com> wrote:

Why not use shoes

- Thomas Perkins

On Nov 19, 2016, at 3:50 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

That's actually what I've been trying to do. But honestly I think sdl is a little Beyond me. I posted up a few different questions seeing if anybody knows where some good tutorials or examples are because with just the stock documentation I'm lost

On Nov 19, 2016 1:45 PM, "Peter Hickman" <peterhickman386@googlemail.com> wrote:
Perhaps Ruby and SDL rather than an external application

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

It's been a while since I did any SDL but this looks like a good place to
start to play audio on linux (maybe OSX)

or if you are comfortable with reading C then this example

would probably be easy to translate

Thank you Peter! I don't know how I missed that when I was going through
rubygems.org! That looks like it could be exactly what I'm looking for I
will get it installed and tested out a little bit and report back. Thanks
again!

···

On Nov 19, 2016 1:59 PM, "Peter Hickman" <peterhickman386@googlemail.com> wrote:

It's been a while since I did any SDL but this looks like a good place to
start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Thomas, thanks for that info. I didn't realize shoes supports audio/video.
I thought it was just a GUI toolkit. I'll definitely be looking into that
and might even use it at some point, but for now I'm actually specifically
trying to create a command line player, but really good to know, I'll
definitely have uses for that. thanks again

···

On Sat, Nov 19, 2016 at 2:03 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

Thank you Peter! I don't know how I missed that when I was going through
rubygems.org! That looks like it could be exactly what I'm looking for I
will get it installed and tested out a little bit and report back. Thanks
again!

On Nov 19, 2016 1:59 PM, "Peter Hickman" <peterhickman386@googlemail.com> > wrote:

It's been a while since I did any SDL but this looks like a good place to
start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I'm looking through the (not very good) documentation for Audite. so far
I'm liking what I'm seeing. it looks like this is exactly what I'm trying
to make here (methods/classes for controlling mpg123) so at least for now I
think I'm close to set! thanks again guys!

one last thing though, I haven't lost hope on using SDL yet though, I just
need some better documentation, tutorials or someone willing to go through
and explain a few things. so if ANYONE can help or knows someone who might
be willing to I would GREATLY appreciate it! Like I've mentioned before,
this current project is just a stepping stone to eventually creating a
softsynth (software synthesizer), and I'm pretty sure I'm going to have to
use SDL for that.

alright, one last time... thank you everyone for all the help! hopefully
I'll be able to report back with some real results soon! lol.

···

On Sat, Nov 19, 2016 at 2:47 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

Thomas, thanks for that info. I didn't realize shoes supports audio/video.
I thought it was just a GUI toolkit. I'll definitely be looking into that
and might even use it at some point, but for now I'm actually specifically
trying to create a command line player, but really good to know, I'll
definitely have uses for that. thanks again

On Sat, Nov 19, 2016 at 2:03 PM, Micky Scandal <mickyscandal@gmail.com> > wrote:

Thank you Peter! I don't know how I missed that when I was going through
rubygems.org! That looks like it could be exactly what I'm looking for I
will get it installed and tested out a little bit and report back. Thanks
again!

On Nov 19, 2016 1:59 PM, "Peter Hickman" <peterhickman386@googlemail.com> >> wrote:

It's been a while since I did any SDL but this looks like a good place
to start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

so I decided for learning purpuses, I'm not going to use the audite gem for
now and want try to use mpg123 directly (since audite uses it as well. so
far I can open a song but when i exit the program the song keeps playing
since mpg123 is still running. so first question, anyone have any ideas how
to exit mpg123 when the ruby script exits? second, I made a stop function
but that's not working either. I get a no method error, but as far as I can
tell I shouldn't (I know I'm doing something wrong though) here's the code:
def open_song
  fork do
    $SONG = %x(mpg123 -q floyd_wish.mp3)
  end
end

def kill_song
  $SONG.kill
end

menu_choice = nil
until [0].include?(menu_choice)
  menu_choice = gets.chomp.to_i
  case menu_choice
  when 1
    open_song
  when 2
    kill_song
  else
    puts "error"
  end
end

now before anyone says it, I know that's really bad code (with the global
variables and whatnot), I'm just trying to get a song to play and stop
before i beautify it lol. but I get the no method error when I select 2
(kill_song). as far as I understand when i call fork it creates a new
thread so $SONG should be a new thread and therefore should respond to
kill right?

···

On Sat, Nov 19, 2016 at 3:07 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

I'm looking through the (not very good) documentation for Audite. so far
I'm liking what I'm seeing. it looks like this is exactly what I'm trying
to make here (methods/classes for controlling mpg123) so at least for now I
think I'm close to set! thanks again guys!

one last thing though, I haven't lost hope on using SDL yet though, I just
need some better documentation, tutorials or someone willing to go through
and explain a few things. so if ANYONE can help or knows someone who might
be willing to I would GREATLY appreciate it! Like I've mentioned before,
this current project is just a stepping stone to eventually creating a
softsynth (software synthesizer), and I'm pretty sure I'm going to have to
use SDL for that.

alright, one last time... thank you everyone for all the help! hopefully
I'll be able to report back with some real results soon! lol.

On Sat, Nov 19, 2016 at 2:47 PM, Micky Scandal <mickyscandal@gmail.com> > wrote:

Thomas, thanks for that info. I didn't realize shoes supports
audio/video. I thought it was just a GUI toolkit. I'll definitely be
looking into that and might even use it at some point, but for now I'm
actually specifically trying to create a command line player, but really
good to know, I'll definitely have uses for that. thanks again

On Sat, Nov 19, 2016 at 2:03 PM, Micky Scandal <mickyscandal@gmail.com> >> wrote:

Thank you Peter! I don't know how I missed that when I was going through
rubygems.org! That looks like it could be exactly what I'm looking for
I will get it installed and tested out a little bit and report back. Thanks
again!

On Nov 19, 2016 1:59 PM, "Peter Hickman" <peterhickman386@googlemail.com> >>> wrote:

It's been a while since I did any SDL but this looks like a good place
to start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I should really do some more poking around before I ask a question. I made
another small script just to test something. I got Thread.kill to work (is
fork something different? because I used Thread.new this time and that
responded to kill) but mpg123 still continued to run after the script. so
short answer, killing the thread won't stop the song, so....what will!?

···

On Sat, Nov 19, 2016 at 8:26 PM, Micky Scandal <mickyscandal@gmail.com> wrote:

so I decided for learning purpuses, I'm not going to use the audite gem
for now and want try to use mpg123 directly (since audite uses it as well.
so far I can open a song but when i exit the program the song keeps playing
since mpg123 is still running. so first question, anyone have any ideas how
to exit mpg123 when the ruby script exits? second, I made a stop function
but that's not working either. I get a no method error, but as far as I can
tell I shouldn't (I know I'm doing something wrong though) here's the code:
def open_song
  fork do
    $SONG = %x(mpg123 -q floyd_wish.mp3)
  end
end

def kill_song
  $SONG.kill
end

menu_choice = nil
until [0].include?(menu_choice)
  menu_choice = gets.chomp.to_i
  case menu_choice
  when 1
    open_song
  when 2
    kill_song
  else
    puts "error"
  end
end

now before anyone says it, I know that's really bad code (with the global
variables and whatnot), I'm just trying to get a song to play and stop
before i beautify it lol. but I get the no method error when I select 2
(kill_song). as far as I understand when i call fork it creates a new
thread so $SONG should be a new thread and therefore should respond to
kill right?

On Sat, Nov 19, 2016 at 3:07 PM, Micky Scandal <mickyscandal@gmail.com> > wrote:

I'm looking through the (not very good) documentation for Audite. so far
I'm liking what I'm seeing. it looks like this is exactly what I'm trying
to make here (methods/classes for controlling mpg123) so at least for now I
think I'm close to set! thanks again guys!

one last thing though, I haven't lost hope on using SDL yet though, I
just need some better documentation, tutorials or someone willing to go
through and explain a few things. so if ANYONE can help or knows someone
who might be willing to I would GREATLY appreciate it! Like I've mentioned
before, this current project is just a stepping stone to eventually
creating a softsynth (software synthesizer), and I'm pretty sure I'm going
to have to use SDL for that.

alright, one last time... thank you everyone for all the help! hopefully
I'll be able to report back with some real results soon! lol.

On Sat, Nov 19, 2016 at 2:47 PM, Micky Scandal <mickyscandal@gmail.com> >> wrote:

Thomas, thanks for that info. I didn't realize shoes supports
audio/video. I thought it was just a GUI toolkit. I'll definitely be
looking into that and might even use it at some point, but for now I'm
actually specifically trying to create a command line player, but really
good to know, I'll definitely have uses for that. thanks again

On Sat, Nov 19, 2016 at 2:03 PM, Micky Scandal <mickyscandal@gmail.com> >>> wrote:

Thank you Peter! I don't know how I missed that when I was going
through rubygems.org! That looks like it could be exactly what I'm
looking for I will get it installed and tested out a little bit and report
back. Thanks again!

On Nov 19, 2016 1:59 PM, "Peter Hickman" <peterhickman386@googlemail.co >>>> > wrote:

It's been a while since I did any SDL but this looks like a good place
to start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Have you looked into the Ruby bindings for OpenAL or FMOD? That’s the
libraries I use for audio in games, etc.

···

On Sun, Nov 20, 2016 at 5:33 AM, Micky Scandal <mickyscandal@gmail.com> wrote:

I should really do some more poking around before I ask a question. I made
another small script just to test something. I got Thread.kill to work (is
fork something different? because I used Thread.new this time and that
responded to kill) but mpg123 still continued to run after the script. so
short answer, killing the thread won't stop the song, so....what will!?

On Sat, Nov 19, 2016 at 8:26 PM, Micky Scandal <mickyscandal@gmail.com> > wrote:

so I decided for learning purpuses, I'm not going to use the audite gem
for now and want try to use mpg123 directly (since audite uses it as well.
so far I can open a song but when i exit the program the song keeps playing
since mpg123 is still running. so first question, anyone have any ideas how
to exit mpg123 when the ruby script exits? second, I made a stop function
but that's not working either. I get a no method error, but as far as I can
tell I shouldn't (I know I'm doing something wrong though) here's the code:
def open_song
  fork do
    $SONG = %x(mpg123 -q floyd_wish.mp3)
  end
end

def kill_song
  $SONG.kill
end

menu_choice = nil
until [0].include?(menu_choice)
  menu_choice = gets.chomp.to_i
  case menu_choice
  when 1
    open_song
  when 2
    kill_song
  else
    puts "error"
  end
end

now before anyone says it, I know that's really bad code (with the global
variables and whatnot), I'm just trying to get a song to play and stop
before i beautify it lol. but I get the no method error when I select 2
(kill_song). as far as I understand when i call fork it creates a new
thread so $SONG should be a new thread and therefore should respond to
kill right?

On Sat, Nov 19, 2016 at 3:07 PM, Micky Scandal <mickyscandal@gmail.com> >> wrote:

I'm looking through the (not very good) documentation for Audite. so far
I'm liking what I'm seeing. it looks like this is exactly what I'm trying
to make here (methods/classes for controlling mpg123) so at least for now I
think I'm close to set! thanks again guys!

one last thing though, I haven't lost hope on using SDL yet though, I
just need some better documentation, tutorials or someone willing to go
through and explain a few things. so if ANYONE can help or knows someone
who might be willing to I would GREATLY appreciate it! Like I've mentioned
before, this current project is just a stepping stone to eventually
creating a softsynth (software synthesizer), and I'm pretty sure I'm going
to have to use SDL for that.

alright, one last time... thank you everyone for all the help! hopefully
I'll be able to report back with some real results soon! lol.

On Sat, Nov 19, 2016 at 2:47 PM, Micky Scandal <mickyscandal@gmail.com> >>> wrote:

Thomas, thanks for that info. I didn't realize shoes supports
audio/video. I thought it was just a GUI toolkit. I'll definitely be
looking into that and might even use it at some point, but for now I'm
actually specifically trying to create a command line player, but really
good to know, I'll definitely have uses for that. thanks again

On Sat, Nov 19, 2016 at 2:03 PM, Micky Scandal <mickyscandal@gmail.com> >>>> wrote:

Thank you Peter! I don't know how I missed that when I was going
through rubygems.org! That looks like it could be exactly what I'm
looking for I will get it installed and tested out a little bit and report
back. Thanks again!

On Nov 19, 2016 1:59 PM, "Peter Hickman" < >>>>> peterhickman386@googlemail.com> wrote:

It's been a while since I did any SDL but this looks like a good
place to start to play audio on linux (maybe OSX)

GitHub - georgi/audite: Portable mp3 player for Ruby

or if you are comfortable with reading C then this example

Play an mp3 with SDL2 · GitHub

would probably be easy to translate

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hi,

got Thread.kill to work (is fork something different?

#fork creates a new process. Thread.new creates a new thread within a
process. These are completely different beasts. A thread is still part
of your program, #fork creates a new program (by copying your old one
first). #exec replaces the running program (if used inside a #fork, the
copy) with a completely different program you start with #exec. As a
result, you have two (semi-)independant programs afterwards (for true
independence more is involved, but that's not the point here).

but mpg123 still continued to run after the script. so short answer,
killing the thread won't stop the song, so....what will!?

Since you want to run an external program, `mp123', placing that in a
separate thread duplicates parallism. Use fork/exec or even betters its
alias #spawn, record the PID, and when your program exits, shoot down
the process playing the audio. Simple example:

    pid = spawn("mp123 -q floyd_wish.mp3") # Same as fork/exec
    # ...Do your other stuff...
    Process.kill("TERM", pid)
    Process.wait

And please stop top-posting and fullquoting. Instead quote only those
parts you actually reply to. There is no need to have three and more
copies of your messages on this list (look at how I quoted in this
message).

Greetings
Marvin

···

On Sat, Nov 19, 2016 at 08:33:05PM -0800, Micky Scandal wrote:

--
Blog: http://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F