fi.hut.tml.xsmiles.gui.media.general
Class AWTMediaContentHandler

java.lang.Object
  extended byfi.hut.tml.xsmiles.content.BaseContentHandler
      extended byfi.hut.tml.xsmiles.gui.media.general.AWTMediaContentHandler
All Implemented Interfaces:
Media, ResourceReferencer, XSmilesContentHandler
Direct Known Subclasses:
MediaContentHandler

public class AWTMediaContentHandler
extends BaseContentHandler
implements XSmilesContentHandler

Handles application/xml This class should be reusable for optimization purposes

Author:
Mikko Honkala

Field Summary
protected  Media media
           
 
Fields inherited from class fi.hut.tml.xsmiles.content.BaseContentHandler
connection, fBrowser, fClosed, fContainer, fDoc, fInputStream, fLink, fMLFCListener, fPrefetched, fPrimary, fShowControls, fStopped, referencedResources
 
Constructor Summary
AWTMediaContentHandler(Media aMedia)
           
 
Method Summary
 void addMediaListener(MediaListener listener)
          Adds a MediaListener for this media.
 void close()
          This will freeze all memory and references to this media.
 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.
 java.lang.String getTitle()
          get the possible title (can be null)
 boolean isStatic()
          Checks if this media is static or continuous.
 void pause()
          Pauses the media.
 void play()
          Plays the media.
 void playPrimary()
           
 void prefetch()
          Prefetches media.
 void setBounds(int x, int y, int width, int height)
          Set the coordinates for the media.
 void setBrowserWindow(BrowserWindow browser)
          sets the browser window instance.
 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 setSoundVolume(int percentage)
          Set the sound volume for media.
 void setURL(XLink url)
          fetches an resource
 void stop()
          Stops the media.
 
Methods inherited from class fi.hut.tml.xsmiles.content.BaseContentHandler
addResource, closeConnection, get, getContainer, getContentStream, getPrimary, getResourceCount, getResourceReferencer, getResources, getXMLDocument, setConnection, setInputStream, setMLFCListener, setPrimary, setUrl, setZoom, showControls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fi.hut.tml.xsmiles.content.XSmilesContentHandler
get, getContentStream, getPrimary, getResourceReferencer, getXMLDocument, setConnection, setInputStream, setMLFCListener, setPrimary, setUrl, setZoom, showControls
 

Field Detail

media

protected Media media
Constructor Detail

AWTMediaContentHandler

public AWTMediaContentHandler(Media aMedia)
Method Detail

setURL

public void setURL(XLink url)
fetches an resource

Specified by:
setURL in interface XSmilesContentHandler
Overrides:
setURL in class BaseContentHandler
Parameters:
url - the documents url, used for relative references

setBrowserWindow

public void setBrowserWindow(BrowserWindow browser)
sets the browser window instance. This is needed mainly by the XMLContentHandler

Specified by:
setBrowserWindow in interface XSmilesContentHandler
Overrides:
setBrowserWindow in class BaseContentHandler

prefetch

public void prefetch()
              throws java.lang.Exception
Description copied from interface: XSmilesContentHandler
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 XSmilesContentHandler
Overrides:
prefetch in class BaseContentHandler
Throws:
java.lang.Exception

play

public void play()
          throws java.lang.Exception
Description copied from interface: XSmilesContentHandler
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 XSmilesContentHandler
Overrides:
play in class BaseContentHandler
Throws:
java.lang.Exception

stop

public void stop()
Description copied from interface: XSmilesContentHandler
Stops the media. The media will be stopped and it will be invisible. Audio will be silent. It is possible to call start() after stop()

Specified by:
stop in interface XSmilesContentHandler
Overrides:
stop in class BaseContentHandler

playPrimary

public void playPrimary()
                 throws java.lang.Exception
Throws:
java.lang.Exception

setContainer

public void setContainer(java.awt.Container container)
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 XSmilesContentHandler
Overrides:
setContainer in class BaseContentHandler
Parameters:
container - This container will contain the media.

close

public void close()
Description copied from interface: XSmilesContentHandler
This will freeze all memory and references to this media. If the media is not yet stopped, it will first be stopped. It is not possible to call start() after close() has been called.

Specified by:
close in interface XSmilesContentHandler
Overrides:
close in class BaseContentHandler

setMediaTime

public void setMediaTime(int millisecs)
This moves the time position in media. Works only for continuous media (video/audio).

Specified by:
setMediaTime in interface XSmilesContentHandler
Overrides:
setMediaTime in class BaseContentHandler
Parameters:
millisecs - Time in millisecs

addMediaListener

public void addMediaListener(MediaListener listener)
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 XSmilesContentHandler
Overrides:
addMediaListener in class BaseContentHandler

isStatic

public boolean isStatic()
Checks if this media is static or continuous.

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

getOriginalDuration

public int getOriginalDuration()
Get the duration of media. Only applicable for continuous media (audio, video).

Specified by:
getOriginalDuration in interface XSmilesContentHandler
Overrides:
getOriginalDuration in class BaseContentHandler
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()
Get the real width of the media. If not visible, or size is unknown, then returns -1.

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

getOriginalHeight

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

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

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
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 XSmilesContentHandler
Overrides:
setBounds in class BaseContentHandler

setSoundVolume

public void setSoundVolume(int percentage)
Set the sound volume for media. Only applicable for sound media formats.

Specified by:
setSoundVolume in interface XSmilesContentHandler
Overrides:
setSoundVolume in class BaseContentHandler
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) )

pause

public void pause()
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 XSmilesContentHandler
Overrides:
pause in class BaseContentHandler

getTitle

public java.lang.String getTitle()
Description copied from interface: XSmilesContentHandler
get the possible title (can be null)

Specified by:
getTitle in interface XSmilesContentHandler


X-Smiles 1.2