org.mycore.datamodel.ifs
Class MCRAudioVideoExtender

java.lang.Object
  extended by org.mycore.datamodel.ifs.MCRAudioVideoExtender
Direct Known Subclasses:
MCRAVExtRealHelix, MCRAVExtVideoCharger

public abstract class MCRAudioVideoExtender
extends Object

For MCRFiles that contain streaming audio/video, instances of this class provide methods to get technical metadata like bitrate, framerate, duration, size etc. and to start a player to stream the asset to a browser.

Version:
$Revision: 15022 $ $Date: 2009-03-26 14:53:00 +0100 (Thu, 26 Mar 2009) $
Author:
Frank Lützenkirchen

Field Summary
static boolean AUDIO
          Constant for media type = audio
protected  String baseMetadata
          The base URL of a cgi that provides technical metadata about the asset
protected  String basePlayerStarter
          The base URL where to get a metafile that starts a player in browser
protected  int bitRate
          The bitrate of the asset in number of bits per second
protected  String contentTypeID
          The content type of the asset
protected  int durationHours
          The hours part of the duration of the asset
protected  int durationMinutes
          The minutes part of the duration of the asset
protected  int durationSeconds
          The seconds part of the duration of the asset
protected  MCRFileReader file
          The asset file this extender belongs to
protected  double frameRate
          The framerate of the asset in number of frames per second
protected  boolean mediaType
          The media type of the asset, either AUDIO or VIDEO
protected  String playerDownloadURL
          The URL where clients can download a player for the asset
protected  String playerStarterCT
          The MIME type a servlet has to send with the player starter
protected  long size
          The size of the asset in bytes
static boolean VIDEO
          Constant for media type = video
 
Constructor Summary
MCRAudioVideoExtender()
          Creates a new MCRAudioVideoExtender.
 
Method Summary
protected  void forwardData(URLConnection connection, OutputStream out)
          Helper method that reads all data from an URLConnection input stream and forwards it to the given output stream.
protected  String getBetween(String prefix, String suffix, String data, String defaultValue)
          Helper method to get a substring that lies between a prefix and a suffix string.
 int getBitRate()
          Returns the maximum number of bits per seconds when asset is streamed
 String getBitRateFormatted()
          Returns the streaming bitrate formatted as a String, e.
protected  URLConnection getConnection(String url)
          Helper method that creates a URLConnection to a given URL and wraps possible IOException or MalformedURLExceptions
protected  int getConnectTimeout()
           
 String getContentTypeID()
          Returns the ID of the content type of this asset
 String getDurationFormatted(String hourLabel, String minutesLabel, String secondsLabel)
          Returns the duration of this asset, formatted as a String for output.
 int getDurationHours()
          Returns the hours part of the duration of this asset
 int getDurationMinutes()
          Returns the minutes part of the duration of this asset
 int getDurationSeconds()
          Returns the seconds part of the duration of this asset
 String getDurationTimecode()
          Returns the duration of the asset, formatted as a timcode, e.
 double getFrameRate()
          Returns the maximum number of frames per second for a streaming video asset
 String getFrameRateFormatted()
          Returns the framerate formatted as a String, e.
 boolean getMediaType()
          Returns the media type, either AUDIO od VIDEO for this asset
protected  String getMetadata(String url)
          Helper method that connects to the given URL and returns the response as a String
 String getPlayerDownloadURL()
          Returns the URL where clients can download a player for this asset
 String getPlayerStarterContentType()
          Returns the MIME type a servlet has to set in the HTTP response that delivers the player starter metafile to the browser
abstract  void getPlayerStarterTo(OutputStream out, String startPos, String stopPos)
          Writes a metafile that starts a streaming player for this asset to an OutputStream, e.
 long getSize()
          Returns the asset size in number of bytes.
 String getSizeFormatted()
          Returns the asset size, formatted as a String.
 void init(MCRFileReader file)
          Initializes this AudioVideoExtender and gets technical metadata from the server that holds the streaming asset.
 boolean isAudio()
          Returns true, if this asset is an audio asset.
 boolean isVideo()
          Returns true, if this asset is a video asset.
 String toString()
          Returns a string representation of this extender's data, useful for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VIDEO

public static final boolean VIDEO
Constant for media type = video

See Also:
Constant Field Values

AUDIO

public static final boolean AUDIO
Constant for media type = audio

See Also:
Constant Field Values

bitRate

protected int bitRate
The bitrate of the asset in number of bits per second


frameRate

protected double frameRate
The framerate of the asset in number of frames per second


mediaType

protected boolean mediaType
The media type of the asset, either AUDIO or VIDEO


durationHours

protected int durationHours
The hours part of the duration of the asset


durationMinutes

protected int durationMinutes
The minutes part of the duration of the asset


durationSeconds

protected int durationSeconds
The seconds part of the duration of the asset


size

protected long size
The size of the asset in bytes


contentTypeID

protected String contentTypeID
The content type of the asset


playerDownloadURL

protected String playerDownloadURL
The URL where clients can download a player for the asset


playerStarterCT

protected String playerStarterCT
The MIME type a servlet has to send with the player starter


basePlayerStarter

protected String basePlayerStarter
The base URL where to get a metafile that starts a player in browser


baseMetadata

protected String baseMetadata
The base URL of a cgi that provides technical metadata about the asset


file

protected MCRFileReader file
The asset file this extender belongs to

Constructor Detail

MCRAudioVideoExtender

public MCRAudioVideoExtender()
Creates a new MCRAudioVideoExtender. The instance has to be initialized by invoking init() before it can be used.

Method Detail

init

public void init(MCRFileReader file)
          throws MCRException
Initializes this AudioVideoExtender and gets technical metadata from the server that holds the streaming asset. Subclasses must override this method!

Parameters:
file - the MCRFile that this extender belongs to
Throws:
MCRException

getBitRate

public int getBitRate()
Returns the maximum number of bits per seconds when asset is streamed

Returns:
the maximum number of bits per seconds when asset is streamed

getBitRateFormatted

public String getBitRateFormatted()
Returns the streaming bitrate formatted as a String, e. g. "1.3 MBit" or "300 kBit".

Returns:
the streaming bitrate formatted as a String

getFrameRate

public double getFrameRate()
Returns the maximum number of frames per second for a streaming video asset

Returns:
the maximum number of frames per second for a streaming video asset

getFrameRateFormatted

public String getFrameRateFormatted()
Returns the framerate formatted as a String, e. g. "25.0"

Returns:
the framerate formatted as a String, e. g. "25.0"

getMediaType

public boolean getMediaType()
Returns the media type, either AUDIO od VIDEO for this asset

Returns:
the media type, compare to the boolean constants in this class

isAudio

public boolean isAudio()
Returns true, if this asset is an audio asset.

Returns:
true, if this asset is an audio asset.

isVideo

public boolean isVideo()
Returns true, if this asset is a video asset.

Returns:
true, if this asset is a video asset.

getDurationHours

public int getDurationHours()
Returns the hours part of the duration of this asset

Returns:
the hours part of the duration of this asset

getDurationMinutes

public int getDurationMinutes()
Returns the minutes part of the duration of this asset

Returns:
the minutes part of the duration of this asset

getDurationSeconds

public int getDurationSeconds()
Returns the seconds part of the duration of this asset

Returns:
the seconds part of the duration of this asset

getDurationFormatted

public String getDurationFormatted(String hourLabel,
                                   String minutesLabel,
                                   String secondsLabel)
Returns the duration of this asset, formatted as a String for output. For example, getDurationFormatted( "Std.", "Min.", "Sek." ) will return the String "1 Std. 15 Min." for an asset that is one hour and 15 minutes long. If duration is less than one hour, only minutes and seconds go into the output string, otherwise hours and minutes are used.

Parameters:
hourLabel - the label for the hours part of the duration
minutesLabel - the label for the minutes part of the duration
secondsLabel - the label for the seconds part of the duration
Returns:
the duration of this asset, formatted as a String

getDurationTimecode

public String getDurationTimecode()
Returns the duration of the asset, formatted as a timcode, e. g. "01:15:00" for an asset thats duration is one hour and 15 minutes.

Returns:
the duration foramatted as a timecode like "hh:mm:ss"

getSize

public long getSize()
Returns the asset size in number of bytes.

Returns:
the asset size in number of bytes

getSizeFormatted

public String getSizeFormatted()
Returns the asset size, formatted as a String.

Returns:
the asset size, formatted as a String

getContentTypeID

public String getContentTypeID()
Returns the ID of the content type of this asset

Returns:
the ID of the content type of this asset

getPlayerDownloadURL

public String getPlayerDownloadURL()
Returns the URL where clients can download a player for this asset

Returns:
the URL where clients can download a player for this asset

getPlayerStarterTo

public abstract void getPlayerStarterTo(OutputStream out,
                                        String startPos,
                                        String stopPos)
                                 throws MCRPersistenceException
Writes a metafile that starts a streaming player for this asset to an OutputStream, e. g. a ServletOutputStream. The browser then streams the asset. The client may provide a start and stop position to play only a certain part of the asset.

Parameters:
out - the OutputStream to write the player starter to
startPos - the optional start position in the format "hh:mm:ss"
stopPos - the optional stop position in the format "hh:mm:ss"
Throws:
MCRPersistenceException

getPlayerStarterContentType

public String getPlayerStarterContentType()
Returns the MIME type a servlet has to set in the HTTP response that delivers the player starter metafile to the browser

Returns:
the MIME type of the player starter metafile

toString

public String toString()
Returns a string representation of this extender's data, useful for debugging.

Overrides:
toString in class Object
Returns:
a String containing useful information about this extender's data

getBetween

protected String getBetween(String prefix,
                            String suffix,
                            String data,
                            String defaultValue)
Helper method to get a substring that lies between a prefix and a suffix string. If either prefix or suffix are not found in the string, the defaultValue is returned. This helper method is used by subclasses to parse metadata that is read from the server.

Parameters:
prefix - the string before the substring
suffix - the string after the substring
data - the string to search through
defaultValue - the default to return when no match is found
Returns:
the substring between prefix and suffix

forwardData

protected void forwardData(URLConnection connection,
                           OutputStream out)
                    throws IOException
Helper method that reads all data from an URLConnection input stream and forwards it to the given output stream.

Parameters:
connection - the URLConnection to get the InputStream from
out - the OutputStream to write the bytes to
Throws:
IOException

getConnection

protected URLConnection getConnection(String url)
                               throws MCRPersistenceException
Helper method that creates a URLConnection to a given URL and wraps possible IOException or MalformedURLExceptions

Parameters:
url - the URL to connect to
Throws:
MCRPersistenceException

getMetadata

protected String getMetadata(String url)
                      throws MCRPersistenceException
Helper method that connects to the given URL and returns the response as a String

Parameters:
url - the URL to connect to
Returns:
the response content as a String
Throws:
MCRPersistenceException

getConnectTimeout

protected int getConnectTimeout()