Sound with Java - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Sound with Java

Description:

Sound file formats you can play. AIFF. AU. WAV. MIDI (type 0 and type 1 files) RMF. Sound Engine ... enables high-quality telephony and video conferencing ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 10
Provided by: mer3
Category:
Tags: aiff | java | sound

less

Transcript and Presenter's Notes

Title: Sound with Java


1
Sound with Java
2
AudioClips
  • You can create and play AudioClips from both
    applets and applications.
  • Sound file formats you can play
  • AIFF
  • AU
  • WAV
  • MIDI (type 0 and type 1 files)
  • RMF

3
Sound Engine
  • Sound API (in many packages)
  • enables high-quality telephony and video
    conferencing applications (Java 1.3)
  • allows professional musicians and sound designers
    to develop new sounds delivered over the Internet
    and used with Java Sound (Java 1.3)
  • allows us to quite easily play sound files (Java
    1.0) what we'll do now

4
java.applet.AudioClip
  • AudioClip interface has these 3 methods
  • void loop()
  • Starts playing this audio clip in a loop
  • void play()
  • Starts playing this audio clip
  • void stop()
  • Stops playing this audio clip

5
construct a new clip with method
java.applet.Applet.newAudioClip
  • Use newAudioClip from Applet class
  • public
  • static final AudioClip newAudioClip(URL url)
  • Get an audio clip from the given URL
  • Parameters
  • url - points to the audio clip
  • Returns
  • the audio clip at the specified URL
  • Since 1.2

6
Need a URL object
  • public URL(String spec) throws MalformedURLExcepti
    on
  • Creates a URL object from the String
    representation. This constructor is equivalent to
    a call to the two-argument constructor with a
    null first argument.
  • Parameters
  • spec - the String to parse as a URL.
  • Throws
  • MalformedURLException - If spec is an unknown
    protocol
  • Need System.getProperty("user.dir") for a String
    representation of the current directory.
  • Need "file" for files in disk, also need file
    name

7
try catch for new URL objects
  • URL could be internet address or file name
  • String fileName "boing.wav" // in current
    folder
  • URL URLaddress null
  • try
  • URLaddress new URL("file" //get current
    folder
  • System.getProperty("user.
    dir")
  • "\\" fileName)
  • catch (MalformedURLException mfurle)
  • System.err.println("Bad URL " mfurle)
  • // String argument "fileC\\mystuff\\boing.wav
    "

8
newAudioClip returns AudioClip
  • Finally, create the AudioClip object with play,
    stop, and loop methods
  • java.applet.AudioClip soundClip
  • Applet.newAudioClip(URLaddress)
  • soundClip.play()
  • // Careful with loop, how will you stop it?

9
Add sound to Five-Dice-Draw
  • Need these imports
  • import
  • Also need to get the sound file in the correct
    folder
  • http//www.geocities.com/SiliconValley/Byte/8867/p
    age6.html
Write a Comment
User Comments (0)
About PowerShow.com