Results 1 to 3 of 3
Thread: Applets having sound
- 03-31-2007, 10:49 AM #1
Member
- Join Date
- Mar 2007
- Posts
- 41
- Rep Power
- 0
- 03-31-2007, 10:53 AM #2
Senior Member
- Join Date
- Mar 2007
- Posts
- 134
- Rep Power
- 0
Hi peiceonly
Playing audio clips in applets is quite simple and involves the following steps:
* Create AudioClip object
* Load .au sound file into AudioClip
* Play sounds once or many within a loop
code is shown below
Java Code:import java.applet.*; AudioClip ac = getAudioClip(getCodeBase(), soundFile); ac.play(); //play once ac.stop(); //stop playing ac.loop(); //play continuously
- 03-31-2007, 10:55 AM #3
Senior Member
- Join Date
- Mar 2007
- Posts
- 134
- Rep Power
- 0
Hi
By the way it wont work for other application other than applets then use
Java Code:import sun.audio.*; //import the sun.audio package import java.io.*; //** add this into your application code as appropriate // Open an input stream to the audio file. InputStream in = new FileInputStream(Filename); // Create an AudioStream object from the input stream. AudioStream as = new AudioStream(in); // Use the static class member "player" from class AudioPlayer to play // clip. AudioPlayer.player.start(as); // Similarly, to stop the audio. AudioPlayer.player.stop(as);
Similar Threads
-
add sound to my applet
By anotsu in forum Java AppletsReplies: 4Last Post: 03-25-2008, 12:26 AM -
Re-playing sound
By JSK in forum CLDC and MIDPReplies: 0Last Post: 02-06-2008, 12:34 PM -
Converting a byte[] into Sound
By savage82 in forum Advanced JavaReplies: 1Last Post: 11-22-2007, 12:57 AM -
applet sound
By marco in forum Java AppletsReplies: 1Last Post: 09-28-2007, 11:31 PM -
Sound in applet Java
By toby in forum Java AppletsReplies: 1Last Post: 08-07-2007, 06:52 AM
Bookmarks