fi.hut.tml.xsmiles.gui.media.swing
Class AudioMedia

java.lang.Object
  extended byfi.hut.tml.xsmiles.gui.media.swing.AudioMedia
All Implemented Interfaces:
Media, java.lang.Runnable

public class AudioMedia
extends java.lang.Object
implements Media, java.lang.Runnable

General implementation for playing audio media, utilizing the javax.sound-technology. Different audio formats can be added by implementing the correct provider and registering AudioMedia as the contents content handler.

Since:
Dec 16, 2003
Version:
$Revision: 5113 $, $Date: 2004-05-17 18:30:42 +0300 (Mon, 17 May 2004) $
Author:
tjjalava

Field Summary
protected static int BUFFER_SIZE
          Size of the byte buffer used while reading the source.
 
Constructor Summary
AudioMedia()
           
 
Method Summary
 void addMediaListener(MediaListener listener)
          Adds a MediaListener for this media.
 void close()
          This will freeze all memory and references to this media.
protected  void finalizeAudio()
          Shuts down the audio stream and releases all resources associated with it.
 int getOriginalDuration()
          Get the duration of media.
 int getOriginalHeight()
          Get the real height of the media.
 int getOriginalWidth()
          Get the real width of the media.
protected  void initAudio()
          Initialized the playback engine by converting the input to an appropriate format and creating an AudioInputStream from the input.
 boolean isStatic()
          Checks if this media is static or continuous.
 void pause()
          Pauses the media.
 void play()
          Plays the media.
 void prefetch()
          Prefetches media.
 void run()
           
 void setBounds(int x, int y, int width, int height)
          Set the coordinates for the media.
 void setContainer(java.awt.Container container)
          Sets the container the media will be rendered in.
 void setMediaTime(int millisecs)
          This moves the time position in media.
 void setMLFCListener(MLFCListener listener)
          All traffic to the browser, such as ComponentFactory, etc goes through this listener.
 void setSoundVolume(int percentage)
          Set the sound volume for media.
 void setUrl(java.net.URL url)
          Sets the URL for this media.
 void showControls(boolean visible)
          Requests the media player to display a control panel for media.
 void stop()
          Stops the media.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

protected static final int BUFFER_SIZE
Size of the byte buffer used while reading the source.

See Also:
Constant Field Values
Constructor Detail

AudioMedia

public AudioMedia()
Method Detail

setMLFCListener

public void setMLFCListener(MLFCListener listener)
Description copied from interface: Media
All traffic to the browser, such as ComponentFactory, etc goes through this listener. If no listener supplied media players should still function with some basic level.

Specified by:
setMLFCListener in interface Media
Parameters:
listener - The MLFCListener supplied by the browser
See Also:
MLFCListener

isStatic

public boolean isStatic()
Description copied from interface: Media
Checks if this media is static or continuous.

Specified by:
isStatic in interface Media
Returns:
true if media is static (duration is zero, see getOriginalDuration().

getOriginalDuration

public int getOriginalDuration()
Description copied from interface: Media
Get the duration of media. Only applicable for continuous media (audio, video).

Specified by:
getOriginalDuration in interface Media
Returns:
The duration of media in millisecs. zero for static media (images, text) -1 means indefinite (infinite streamed media or unknown duration).

getOriginalWidth

public int getOriginalWidth()
Description copied from interface: Media
Get the real width of the media. If not visible, or size is unknown, then returns -1.

Specified by:
getOriginalWidth in interface Media
Returns:
Original width of the media. -1 means no particular width (audio) or unknown width (text, XML media...)

getOriginalHeight

public int getOriginalHeight()
Description copied from interface: Media
Get the real height of the media. If not visible, or size is unknown, then returns -1.

Specified by:
getOriginalHeight in interface Media
Returns:
Original height of the media. -1 means no particular height (audio) or unknown height (text, XML media...)

setUrl

public void setUrl(java.net.URL url)
Description copied from interface: Media
Sets the URL for this media. This method will only set the URL for the media. To actually download the data, prefetch() or play() should be called.

Specified by:
setUrl in interface Media
Parameters:
url - URL for media

setContainer

public void setContainer(java.awt.Container container)
Description copied from interface: Media
Sets the container the media will be rendered in. If media is audio, this can be null. Can be called if media is already visible in one container, it will then move to the new container.

Specified by:
setContainer in interface Media
Parameters:
container - This container will contain the media.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Description copied from interface: Media
Set the coordinates for the media. These are relative to the given container, set using setContainer(). Setting the bounds will always immediately move the media to a new location, if it is visible.

Specified by:
setBounds in interface Media

setSoundVolume

public void setSoundVolume(int percentage)
Description copied from interface: Media
Set the sound volume for media. Only applicable for sound media formats.

Specified by:
setSoundVolume in interface Media
Parameters:
percentage - Sound volume, 0-100- (0 is quiet, 100 is original loudness, 200 twice as loud; dB change in signal level = 20 log10(percentage / 100) )

prefetch

public void prefetch()
              throws java.lang.Exception
Description copied from interface: Media
Prefetches media. The URL must have been set using setUrl(). The data will be downloaded from the URL. After calling this method, the media will be in memory and can be played. This is a blocking method.

Specified by:
prefetch in interface Media
Throws:
java.lang.Exception

play

public void play()
          throws java.io.IOException
Description copied from interface: Media
Plays the media. The media will be added to the container set using setContainer(). It will be visible. It will also play any animation it possibly has. Also, audio media is started using this method.

If the media is not yet prefetched, it will first be prefetched.

Specified by:
play in interface Media
Throws:
java.io.IOException

pause

public void pause()
Description copied from interface: Media
Pauses the media. The media will stay visible, but any animations will be paused. Audio media will be silent. NOT IMPLEMENTED YET. ?How to restart paused media?

Specified by:
pause in interface Media

stop

public void stop()
Description copied from interface: Media
Stops the media. The media will be stopped and it will be invisible. Audio will be silent.

Specified by:
stop in interface Media

close

public void close()
Description copied from interface: Media
This will freeze all memory and references to this media. If the media is not yet stopped, it will first be stopped.

Specified by:
close in interface Media

setMediaTime

public void setMediaTime(int millisecs)
Description copied from interface: Media
This moves the time position in media. Works only for continuous media (video/audio).

Specified by:
setMediaTime in interface Media
Parameters:
millisecs - Time in millisecs

addMediaListener

public void addMediaListener(MediaListener listener)
Description copied from interface: Media
Adds a MediaListener for this media. The listener will be called
  1. When the media has been prefetched. (NOT IMPLEMENTED YET).
  2. When the media ends. (continuous media, video/audio)
Static media, such as text and images will end immediately, notifying immediately about the end of media.

Specified by:
addMediaListener in interface Media

showControls

public void showControls(boolean visible)
Description copied from interface: Media
Requests the media player to display a control panel for media. For audio and video, these can be a volume/play/stop controls, for images, these can be zoom controls etc. The controls are GUI dependent, generated through ComponentFactory.

Specified by:
showControls in interface Media
Parameters:
visible - true=Display controls, false=don't display controls.

initAudio

protected void initAudio()
                  throws javax.sound.sampled.UnsupportedAudioFileException,
                         java.io.IOException,
                         javax.sound.sampled.LineUnavailableException
Initialized the playback engine by converting the input to an appropriate format and creating an AudioInputStream from the input.

Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException
javax.sound.sampled.LineUnavailableException

finalizeAudio

protected void finalizeAudio()
Shuts down the audio stream and releases all resources associated with it.


run

public void run()
Specified by:
run in interface java.lang.Runnable


X-Smiles 1.2