Audio
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

Audio PowerPoint PPT Presentation


  • 171 Views
  • Uploaded on
  • Presentation posted in: General

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.

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Audio

Audio

Chapter 17 - Student


Audio files

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


Audio1

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


Audio2

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


Audio3

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


Audio need for stop

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


Stop method

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


Summary

Summary

  • Supported audio file types

  • AudioClip

  • Methods on AudioClip

    • play

    • loop

    • stop

  • Need for stop( ) method

(c) 2005 by Elizabeth Sugar Boese


  • Login