1 / 8

Audio

Audio. Chapter 17 - Student. Audio Files. Java can play the following audio types: .au (Sun Audio) .wav (Windows Wave) .aif or .aiff (Macintosh AIFF) .mid (Musical Instrument Digital Interface (MIDI) .rmf.

herne
Télécharger la présentation

Audio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Audio Chapter 17 - Student

  2. Audio Files • Java can play the following audio types: • .au (Sun Audio) • .wav (Windows Wave) • .aif or .aiff (Macintosh AIFF) • .mid (Musical Instrument Digital Interface (MIDI) • .rmf Note: mp3 is NOT supported in the Java API. However, There are libraries you can download and use Note: wav files from your CDs are HUGE! Won’t run well – only use small WAV files (c) 2005 by Elizabeth Sugar Boese

  3. Audio getCodeBase works same for images as audio files AudioClip clip; clip = getAudioClip( getCodeBase( ), audioFilename ); clip.play( ); • There are three methods we can call on our AudioClip • play play the sound file once through • loop play the sound file continually • stop stop playing the file (c) 2005 by Elizabeth Sugar Boese

  4. Audio import java.awt.*; import java.applet.*; import javax.swing.*; public class AudioPlay extends JApplet { String audioFilename = "mySounds.mid"; AudioClip ac; public void init( ) { ac = getAudioClip( getCodeBase( ), audioFilename ); ac.play( ); } } (c) 2005 by Elizabeth Sugar Boese

  5. Audio To have sound clip loop: • get an AudioClip • call the loop( ) method import java.awt.*; import java.applet.*; import javax.swing.*; public class AudioPlay extends JApplet { String audioFilename = "mySounds.mid"; AudioClip ac; public void init( ) { ac = getAudioClip( getCodeBase( ), audioFilename ); ac.loop( ); } } (c) 2005 by Elizabeth Sugar Boese

  6. Audio: Need for stop( ) • See Example • Each button starts an audio file playing • If the previous one isn’t stopped first, then the new one plays on TOP of the other one • This is usually not desired However, some applications want this technique (see example of Singing Horses on Internet at: http://svt.se/hogafflahage/hogafflaHage_site/Kor/hestekor.swf (c) 2005 by Elizabeth Sugar Boese

  7. stop method Stop playing audio when user leaves the applet: • Write a stop method import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class LoopAudio extends JApplet { String audioFilename = "happyDaze.wav"; AudioClip ac; public void init( ) { ac = getAudioClip( getCodeBase( ), audioFilename ); ac.loop( ); // loop instead of play } public void stop( ) { if( ac != null )// can't stop it if it isn't running, check first ac.stop( ); } } (c) 2005 by Elizabeth Sugar Boese

  8. Summary • Supported audio file types • AudioClip • Methods on AudioClip • play • loop • stop • Need for stop( ) method (c) 2005 by Elizabeth Sugar Boese

More Related