Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Sounds?

Author Message
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

How do I play a sound with JavaScript?

I just want play a wav or something when a function is called...

Thanks!
View user's profile Send private message Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

That what would've been bad because I assume you mean that I would get javascript to play the beeper sound every second or so, which would then have to load each time.

Yeah, that's the only way I could see it not playing smoothly - looping for me with quicktime was always rather smooth. Must be the Tiger build (as you originally said)...

Do you want the .java file

Yes please
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

But you'd only have to call play() when the time reaches that for when the alarm is set, wouldn't you? If it's looping, doesn't it just keep going till you then tell it to stop? I'm gonna play around with it, as I am now officially intrigued

Yeah that's what I meant - if you use the loop() method. However when you said:

Were you trying to do it programmatically with javascript

That what would've been bad because I assume you mean that I would get javascript to play the beeper sound every second or so, which would then have to load each time.

But no, I used the loop() method. Do you want the .java file?
View user's profile Send private message Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

every time you call the play() method, it would load it, then play it. Which would be baaaad

But you'd only have to call play() when the time reaches that for when the alarm is set, wouldn't you? If it's looping, doesn't it just keep going till you then tell it to stop? I'm gonna play around with it, as I am now officially intrigued

Download my AlarmClock gadget and check out the code/java class if you like (see the front page of dashboarder).

I already have done Wink
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

I set the loop parameter to true.

Reading the java documentation for the AudioClip class, I found that it doesn't preload the sound file, so every time you call the play() method, it would load it, then play it. Which would be baaaad

Download my AlarmClock gadget and check out the code/java class if you like (see the front page of dashboarder).
View user's profile Send private message Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

Out of interest, how were you making the wav loop? Were you trying to do it programmatically with javascript or setting the loop parameter to true?
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

I've written an itsy bitsy teeny weeny Java Applet to play sounds for me
View user's profile Send private message Visit poster's website Widgets
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

Is it just me or is quicktime really slow in the tiger preview? I can't get a teeny wav (beeping sound) to loop without stuttering and cutting out. Is there an alternative to quicktime?
View user's profile Send private message Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

Use the quicktime plug-in. I've only ever done this using moz, but i assume it will work with gadgets/Safari.

see here: http://developer.apple.com/documentation/QuickTime/REF/QT41_HTML/QT41W hatsNew-80.html
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
joephish



Joined: 27 Mar 2005
Posts: 17
Location: Scotland

Posted: Fri Aug 27, 2004 - 10:53 am    Post subject: Imported from The Dashboader Reply with quote

The current version of QuickTime def seems to be naaaaasty. I can't export anything in preview or qt player without it crashing, and it can't play the iMovie I was working on at all really.

Anyway, the java - it's really small so I'll just paste it here. Hopefully this'll work...

import java.net.*;
import java.applet.AudioClip;

public class SoundPlay extends java.applet.Applet {
private String sound;
private AudioClip audio;

/* play the clip */
private void doPlay(boolean looping) {
try {
if (audio != null) {
audio.stop();
audio = null;
}

if (sound.length() > 0) {
audio = getAudioClip(new URL(getDocumentBase(), sound));
if(looping)
audio.loop();
else
audio.play();
}
} catch(Exception e) {}
}
public void play() { doPlay(false); }
public void loop() { doPlay(true); }

/* Initialize the applet, get the "snd" attribute. */
public void init() {
sound = getParameter("snd");
}

/* When the applet is stopped, stop playing the sound. */
public void stop() {
if (audio != null) {
audio.stop();
audio = null;
}
}
}
View user's profile Send private message Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group