Adding sound to Rails app


#1

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


#2

Bill -

On 2-Dec-08, at 11:28 AM, Bill W. 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-but-not-flash

hth,
Jodi


#3

On 2 Dec 2008, at 16:50, Jodi S. wrote:

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

Fred


#4

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…


#5

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


#6

On 02 Dec 2008, at 22:04, Bill W. 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


#7

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


#8

actually, on second thoughts, Peter’s solution looks much better


#9

Hi Fred,

Frederick C. 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


#10

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