com.quadrique.jbuildingblocks.core.sound
Class JbbSoundHandler

java.lang.Object
  extended by com.quadrique.jbuildingblocks.core.sound.JbbSoundHandler

public class JbbSoundHandler
extends Object

This class provides convenience routine to manipulate sound files. The underlying implementation is based on the Java Sound APIs

Author:
Hervé Rivere

Method Summary
 void addListener(JbbSoundHandlerListener zListener)
          Call this method to register and to be notified of start/stop palying/recording events
 void createSoundFile()
           
 AudioFormat getSoundFileFormat(File zFile)
           
 byte[] getSoundFileRawDataByte(File zFile)
           
 Exception hasProblemOcuredDuringPlay()
           
static JbbSoundHandler newInstance()
           
 void removeListener(JbbSoundHandlerListener zListener)
          Call this method to remove a previously registered listener
 void startPlaying(File zFile, boolean zIsAsynchronous)
          this method plays a sound file in a synchronous manner (i.e.
 void startRecording(File zFile, boolean zUseCdQuality)
          start recording to the given file.
 void stopPlaying()
           
 void stopRecording()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static JbbSoundHandler newInstance()
Returns:
a new instance

startPlaying

public void startPlaying(File zFile,
                         boolean zIsAsynchronous)
                  throws Exception
this method plays a sound file in a synchronous manner (i.e. the method returns when the sound file has been entirely played) or in an asynchronous manner (i.e. a separate thread is kicked off to play the sound file). If you use the asynchronous manner, you can call the stopPlaying() method to stop playing the file at any time (i.e. you don't need to wait until the end) If you use the asynchronous manner, you can call the hasProblemOcuredDuringPlay() method to determine if any problem occured while the sound file was being played.

Parameters:
zFile - the input sound file
zIsAsynchronous - if true, the method kicks-off a separate thread and returns as soon as the thread has been started. If false, the method plays the sound file in its entirety before returning.
Throws:
Exception - if an error occurs

stopPlaying

public void stopPlaying()
Throws:
Exception

hasProblemOcuredDuringPlay

public Exception hasProblemOcuredDuringPlay()
Returns:
null if no problem occured during the playback, the corresponding exception otherwise

getSoundFileFormat

public AudioFormat getSoundFileFormat(File zFile)
                               throws Exception
Parameters:
zFile - the input sound file
Returns:
the AudioFormat instance that describes the formatting of the given sound file. You can use the AudioFormat.getEncoding(),getChannels(),getSampleRate(),getSampleSizeInBits()... methods to get the corresponding information.
Throws:
Exception - if an error occurs

getSoundFileRawDataByte

public byte[] getSoundFileRawDataByte(File zFile)
                               throws Exception
Parameters:
zFile - the input file
Returns:
the byte array that corresponds to the raw sound data (i.e. without any header information)
Throws:
Exception - if an error occurs

createSoundFile

public void createSoundFile()
                     throws Exception
Throws:
Exception

startRecording

public void startRecording(File zFile,
                           boolean zUseCdQuality)
                    throws Exception
start recording to the given file. To stop the recording, use the stopRecording() method

Parameters:
zFile - the file to use to save the recorded audio
zUseCdQuality - true to record with CD quality (44,1 Khz, stereo, 16 bits) or false to use 8Khz 8bit mono
Throws:
Exception - if an error occurs

stopRecording

public void stopRecording()
                   throws Exception
Throws:
Exception

addListener

public void addListener(JbbSoundHandlerListener zListener)
                 throws Exception
Call this method to register and to be notified of start/stop palying/recording events

Parameters:
zListener - a reference to an instance of a class that implements the SoundHandlerListener interface.
Throws:
Exception - if an error occurs

removeListener

public void removeListener(JbbSoundHandlerListener zListener)
Call this method to remove a previously registered listener

Parameters:
zListener - a reference to an instance of a class that implements the SoundHandlerListener interface.
See Also:
JbbSoundHandlerListener


Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.