PenProfile 2.x

com.livescribe.ui
Class MediaPlayer

java.lang.Object
  extended by com.livescribe.ui.MediaPlayer

public class MediaPlayer
extends Object

MediaPlayer allows various media to be played. It provides methods for implementing AUI (Audio User Interface). Since the system cannot read the resources from the penlet jars, the class is made as abstract and provides a method to get the resource stream from the penlet. The following is how the penlet can use the MediaPlayer

 this.mediaPlayer = new com.livescribe.ui.MediaPlayer() {
     protected InputStream getResourceAsStream(String resource) {
         return getClass().getResourceAsStream(resource);
     }
 };
 this.mediaPlayer.play("/audio/foo.mp3");
 this.mediaPlayer.play("file:///a/b/c.wav");
 this.mediaPlayer.playAudioForNumber(5423);
 

The methods allow you to play a one or more audio file back to back. The API allows the caller to block till one or more clips has finished playing. The default methods do not wait till the playback finishes and returns immediately after starting the playback.


Method Summary
static String getMimeType(String file)
          Returns the MIME type of the specified audio file.
protected  InputStream getResourceAsStream(String resource)
          Allows the penlet to provide the stream for the resource specified.
 boolean isAudioPlayerPlaying()
          Check if a audio is currently being played.
 boolean isMoviePlaying()
          Check if a movie is currently being played.
static MediaPlayer newInstance(Penlet penlet)
          Create a new instance of MediaPlayer.
 void play(AudibleResource audibleResource)
          Plays an audible resource object
 void play(InputStream stream, String mimeType)
          Plays the stream without waiting for it to finish playing
 void play(InputStream stream, String mimeType, boolean wait)
          Plays the stream with the option of waiting for the clip to finish playing.
 void play(InputStream stream, String mimeType, boolean wait, int startOffset, int byteCount)
          Seeks to the position specified by startOffset and plays the stream for byteCount bytes.
 void play(String clip)
          Plays the clip without waiting for it to finish playing
 void play(String[] clips)
           
 void play(String[] clips, boolean wait)
           
 void play(String clip, boolean wait)
          Plays the clip with the option of waiting for the clip to finish playing.
 void playAPM(InputStream stream, String mimeType)
          Plays an APM [ Audio Punctuation Mark ].
 void playAPM(String clip)
          Plays an APM [ Audio Punctuation Mark ].
 void playAudioForNumber(int number)
          Plays the audio for the number specified.
 void playMovie(String[] audio, String[] frame)
          Play a movie.
 void playMovieRepeatedly(String[] audio, String[] frame)
          Play a movie repeatedly.
 void stop()
          Stops the MediaPlayer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static MediaPlayer newInstance(Penlet penlet)
Create a new instance of MediaPlayer.

Parameters:
penlet - if a non-null value is passed, then media player can lookup resource names on the penlet's jar file and play. If null is passed, then the above feature will not be supported. Platform code should pass null.
Returns:
an instance of a new MediaPlayer

playAPM

public final void playAPM(InputStream stream,
                          String mimeType)
Plays an APM [ Audio Punctuation Mark ].

Parameters:
stream - The InputStream for the APM.
mimeType - The mime type for this APM.

playAPM

public final void playAPM(String clip)
Plays an APM [ Audio Punctuation Mark ].

Parameters:
clip - URL or a path name in the jar of the resource.

play

public final void play(AudibleResource audibleResource)
Plays an audible resource object

Parameters:
audibleResource - the AudibleResource
Since:
0.4

play

public final void play(InputStream stream,
                       String mimeType)
Plays the stream without waiting for it to finish playing

Parameters:
stream - the InputStream that contains the media data to play to play
mimeType - the content type of the media

play

public final void play(InputStream stream,
                       String mimeType,
                       boolean wait)
Plays the stream with the option of waiting for the clip to finish playing.

Parameters:
stream - the InputStream that contains the media data to play.
mimeType - the content type of the media.
wait - true to wait till the clip finishes playing; false not to wait.

play

public final void play(InputStream stream,
                       String mimeType,
                       boolean wait,
                       int startOffset,
                       int byteCount)
Seeks to the position specified by startOffset and plays the stream for byteCount bytes. This does nothing if the input stream or MIME type are null.

Parameters:
stream - the input stream for the media data
mimeType - the media MIME type
wait - true to wait until the clip finishes playing and false to not wait
startOffset - the absolute offset in the stream where the stream should be positioned for playback. A value less than 0 is ignored and the stream plays from the start.
byteCount - number of bytes from the offset to play. This must be a positve value.
Since:
0.6

play

public final void play(String clip)
Plays the clip without waiting for it to finish playing

Parameters:
clip - URL or a path name in the jar of the resource

play

public final void play(String clip,
                       boolean wait)
Plays the clip with the option of waiting for the clip to finish playing.

Parameters:
clip - URL or a path name in the jar of the resource
wait - true to wait till the clip finishes playing; false not to wait.

play

public final void play(String[] clips)
Parameters:
clips - Array of URLs or a path names in the jar of the resource. the resource

play

public final void play(String[] clips,
                       boolean wait)
Parameters:
clips - Array of URLs or a path names in the jar of the resource.
wait - true to wait till the clip finishes playing false not to wait.

stop

public void stop()
Stops the MediaPlayer


playAudioForNumber

public final void playAudioForNumber(int number)
Plays the audio for the number specified.

Parameters:
number - The number that needs to be announced, e.g. one, two, three, etc. for one to ten

isMoviePlaying

public boolean isMoviePlaying()
Check if a movie is currently being played.

Returns:
if the movie is playing; otherwise.

isAudioPlayerPlaying

public boolean isAudioPlayerPlaying()
Check if a audio is currently being played.

Returns:
if the audio is playing; otherwise.

playMovieRepeatedly

public void playMovieRepeatedly(String[] audio,
                                String[] frame)
Play a movie repeatedly. When the animation is completed it loops back.

Parameters:
audio - An array of the audio corresponding to each sub movie
frame - An array of the images corresponding to each sub movie

playMovie

public void playMovie(String[] audio,
                      String[] frame)
Play a movie.

Parameters:
audio - An array of the audio corresponding to each sub movie
frame - An array of the images corresponding to each sub movie sub movie

getResourceAsStream

protected InputStream getResourceAsStream(String resource)
Allows the penlet to provide the stream for the resource specified.

Parameters:
resource - the URL or path of the audio resource.
Returns:
the InputStream.

getMimeType

public static String getMimeType(String file)
Returns the MIME type of the specified audio file. If the file is null then this will return null. If the type could not be determined, then this returns a default of "audio/wav".

Parameters:
file - get the MIME type of this file
Returns:
the file's MIME type, null if the specified file is null, or a default of "audio/wav" if the type could not be determined.

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.