Forum: Ruby on Rails adding sound to Rails app

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.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2008-12-02 17:29
(Received via mailing list)
I need to add some simple sounds to my latest app.  Basically, 'beep'
and 'burp'.  Google hasn't been much help.  I'd appreciate any
recommendations.

Thanks,
Bill
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2008-12-02 17:52
(Received via mailing list)
Bill -

On 2-Dec-08, at 11:28 AM, Bill Walton wrote:

> I need to add some simple sounds to my latest app.  Basically,
> 'beep' and 'burp'.  Google hasn't been much help.  I'd appreciate
> any recommendations.
>
> Thanks,
> Bill

as this is a client capability the answer will be found in a java ref:

This ajaxian article looks good:

http://ajaxian.com/archives/sound-with-javascript-...

hth,
Jodi
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-02 18:13
(Received via mailing list)
On 2 Dec 2008, at 16:50, Jodi Showers wrote:

>
scriptaculous also has a simple sound thingy
(http://github.com/madrobby/scriptaculous/wikis/sound
)

Fred
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2008-12-02 22:05
(Received via mailing list)
Hi Fred,

Frederick Cheung wrote:
> >
> scriptaculous also has a simple sound thingy
(http://github.com/madrobby/scriptaculous/wikis/sound
> )

Thanks.  I found that a bit after my initial plea and grabbed sound.js.
I'm
having a really wierd problem with it though.  I call
Sound.play(good_sound)
or Sound.play(bad_sound) depending on whether or not an item is found.
First time it works correctly, playing the correct sound.  Second time,
it
plays the last sound, then the correct sound.  Works that way from then
on.
I'm logging the calls to Sound.play and it's only getting called once
per
request/response.  But the sound's getting played twice.  I've scratched
my
head raw.  Any idea what I might be doing wrong?

Thanks,
Bill
5eb57ea1f36182bdd64e5601a73262e6?d=identicon&s=25 Nellboy (Guest)
on 2008-12-03 00:40
(Received via mailing list)
sounds like you have to load the sound first to play it?... i'd be
looking at the sequence of events from the time it's first triggered,
and in what order the sound is loaded... the way i'd approach this
would to call a function which first loads the correct sound and then
plays it...

def play_correct_sound(input_value)
  if input_value = 'good'
    correct_sound = good_sound
  else
    correct_sound = bad_sound
  end
  Sound.play(correct_sound)
end

I could be wrong though...
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2008-12-03 02:40
(Received via mailing list)
Hi Nellboy,

Nellboy wrote:

> i'd be looking at the sequence of events from the
> time it's first triggered, and in what order the sound
> is loaded...

I'm not sure what you mean by 'order the sound is loaded'.  Order
relative
to what?  I'm looking at the js execution in FF.  The double dinging is
intermittent now and I haven't been able to isolate the cause yet.  When
it
starts, though, it can be replicated.  What's really wierd is that I can
put
a breakpoint at the beginning of the Sound.play function and the app
dings
before it ever gets there.  Then it dings again at the expected point
within
the function.

> the way i'd approach this would to call a function
> which first loads the correct sound and then plays it...

Thanks much for the suggestion.  It's helped.  I just pulled the url
string
out of the call to Sound.play and replaced it with a variable to which
I'd
just assigned the string.  The problem still happens, but not as much.

Any other ideas are very, very welcome.

Thanks,
Bill
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2008-12-03 11:57
(Received via mailing list)
On 02 Dec 2008, at 22:04, Bill Walton wrote:

> once per
> request/response.  But the sound's getting played twice.  I've
> scratched my
> head raw.  Any idea what I might be doing wrong?


You do add the {replace: true} option right?

if (!(typeof Sound == 'undefined')) {
    Sound.play('/sounds/'+somestring+'.mp3', {replace: true});
}


Best regards

Peter De Berdt
5eb57ea1f36182bdd64e5601a73262e6?d=identicon&s=25 Nellboy (Guest)
on 2008-12-03 13:05
(Received via mailing list)
no problem Bill... The solution is just to keep playing with it, and
recoding it in different ways until it works...  if my suggestion
helped, then I think it probably has got something to do with the way
the Sound.play function is executing... from what you say, i suspect
that it's not clearing the previous sound out of cache before loading
the next one - I've seen something like that before but not in
Rails... you could try something like this to see if that's the case:

def play_correct_sound(input_value)
  if input_value = 'good'
    correct_sound = good_sound
  elsif input_value = 'bad'
    correct_sound = bad_sound
  else
    correct_sound = nil
  end
  Sound.play(correct_sound)
end

good luck
5eb57ea1f36182bdd64e5601a73262e6?d=identicon&s=25 Nellboy (Guest)
on 2008-12-03 13:07
(Received via mailing list)
actually, on second thoughts, Peter's solution looks much better
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2008-12-03 23:18
(Received via mailing list)
Hi Peter,

Sorry it took me so long to respond.  I wanted to make sure of my facts
re:
your first question.

> You do add the {replace: true} option right?
>
> if (!(typeof Sound == 'undefined')) {
>    Sound.play('/sounds/'+somestring+'.mp3', {replace: true});
> }

I'm making the call to Sound.play in an RJS view, so the code looks a
little
different.  As an example...

right_sound = "sounds/item_deleted.wav"
page.call "Sound.play", right_sound, true

It took some experiementation to figure out that the last argument to
page.call needed to be the constant and not some string.  I double
checked
today and modifying the call leads to bad results re: the value of
'replace'.  The code above gives the best results I've achieved so far.
But
I'm getting very different results depending on whether I'm running the
RoR
stack locally on windows vs. on a shared (linux) host.  I'm also getting
different results on the hosted system depending on whether I'm running
my
browser on windows or linux.  It's pretty solid running the RoR stack
locally, along with the browser (FF) on windows.  Running RoR on a
shared
linux host with browser on Windows is worse.  With browser on Linux...

I've got 3 sounds and 3 .wav files: beep, burp, and swoosh.  burp and
swoosh
are both 3KB files. beep is 121KB.  Running my browser on Linux, I only
hear
the beep (sometimes a two-fer).  I went onto the server and copied
beep.wav
over burp.wav.  Now i can hear burp (although it's beep, of course).
Change
back to the original burp file and the sound disappears.

I've stepped through the js and the code is only getting called once.
But
once it starts 'bouncing', the sound is produced before the library
function's first line gets executed.  I'm at a loss as to where to look
for
the problem.  Any direction / suggestions will be very much appreciated.

TIA,
Bill
This topic is locked and can not be replied to.