com.adobe.mediacore
Class DefaultMediaPlayer

java.lang.Object
  extended by com.adobe.mediacore.DefaultMediaPlayer
All Implemented Interfaces:
MediaPlayer

public final class DefaultMediaPlayer
extends Object
implements MediaPlayer

Default implementation of MediaPlayer interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.adobe.mediacore.MediaPlayer
MediaPlayer.AdPlaybackEventListener, MediaPlayer.DRMEventListener, MediaPlayer.Event, MediaPlayer.EventListener, MediaPlayer.PlaybackEventListener, MediaPlayer.PlayerState, MediaPlayer.QOSEventListener, MediaPlayer.Visibility
 
Field Summary
 
Fields inherited from interface com.adobe.mediacore.MediaPlayer
LIVE_POINT
 
Method Summary
 void addEventListener(MediaPlayer.Event event, MediaPlayer.EventListener listener)
          Adds a new event listener for specified event type.
static MediaPlayer create(Context context)
          Convenience method for creating a media player.
 BufferControlParameters getBufferControlParameters()
           
 TimeRange getBufferedRange()
          Returns the buffered range.
 TextFormat getCCStyle()
           
 MediaPlayer.Visibility getCCVisibility()
           
 MediaPlayerItem getCurrentItem()
          Gets the current media player item.
 long getCurrentTime()
          The current playhead time as reported by the underlying components.
 DRMManager getDRMManager()
           
 NotificationHistory getNotificationHistory()
           
 PlaybackMetrics getPlaybackMetrics()
           
 TimeRange getPlaybackRange()
           
 TimeRange getSeekableRange()
          Returns the seekable range
 MediaPlayer.PlayerState getStatus()
          Returns the media player status.
 Timeline getTimeline()
          The current timeline containing both main content and associated alternate content (ads).
 MediaPlayerView getView()
          Returns the view where the media player will render the images.
 void pause()
          Pauses the playback of the current media item.
 void play()
          Initiates or resumes the playback of the current media item.
 void prepareToPlay()
          Prepares to play the current selected item.
 void prepareToPlay(long position)
          Prepares to play the current selected item.
 void registerAdClientFactory(AdClientFactory adClientFactory)
          Sets a custom AdvertisingFactory to be used in the ad placement process.
 void release()
          Releases media player object.
 void removeEventListener(MediaPlayer.Event event, MediaPlayer.EventListener listener)
          Removes an existing event listener for specified event type.
 void replaceCurrentItem(MediaResource resource)
          Replaces the current media item or sets one if none exists.
 void reset()
          Resets the media player to its uninitialized state.
 void seek(long position)
          Moves the play head to specified position.
 void setABRControlParameters(ABRControlParameters params)
          Set the parameters that control the playback of MBR content.
 void setBufferControlParameters(BufferControlParameters params)
          Set the parameters that control the media player buffer.
 void setCCStyle(TextFormat textFormat)
          Sets the closed captioning style.
 void setCCVisibility(MediaPlayer.Visibility visibility)
          Sets the visibility of closed captioning.
protected  void setStatus(MediaPlayer.PlayerState state, MediaPlayerNotification.Error error)
           
 void setVolume(int volume)
          Change the media player volume.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static MediaPlayer create(Context context)
Convenience method for creating a media player.

Parameters:
context - Application context provided by the developer.
Returns:
default library implementation of media player interface.

prepareToPlay

public void prepareToPlay()
                   throws IllegalStateException
Description copied from interface: MediaPlayer
Prepares to play the current selected item. If the client calls play() directly and the media item is not yet ready to play, the media player will invoke this method automatically. Calling this function will eventually lead to enter playback using default values Video on demand content will start at 0 and live streaming will start from the client live point.

Specified by:
prepareToPlay in interface MediaPlayer
Throws:
IllegalStateException - if the media player is not in initialized mode.

prepareToPlay

public void prepareToPlay(long position)
                   throws IllegalStateException
Description copied from interface: MediaPlayer
Prepares to play the current selected item. If the client calls play() directly and the media item is not yet ready to play, the media player will invoke this method automatically. Calling this function will eventually lead to enter playback at a specified position that is contained in the seekable range. If the specified position is not contained in the seekable range, this position will be readjusted to the default starting values. For video on demand, the position will be readjusted to the beginning of the content. For live content, the position will be readjusted to the client live point.

Specified by:
prepareToPlay in interface MediaPlayer
Parameters:
position - Position to enter the stream
Throws:
IllegalStateException - if the media player is not in initialized mode.

play

public void play()
          throws IllegalStateException
Description copied from interface: MediaPlayer
Initiates or resumes the playback of the current media item. If the current media item is not yet ready to play it will invoke prepareToPlay first. If the current media item was paused, then invoking this command will resume the playback from where it was paused, otherwise it will start the playback from the beginning. If the current media item was already playing, calling this method will have no effect.

Specified by:
play in interface MediaPlayer
Throws:
IllegalStateException - if the media player is in a state different from PAUSED, READY or PLAYING state.

pause

public void pause()
           throws IllegalStateException
Description copied from interface: MediaPlayer
Pauses the playback of the current media item. If the current media item was already paused, calling this method will have no effect. In order to resume the playback of the current media item, call play() method.

Specified by:
pause in interface MediaPlayer
Throws:
IllegalStateException - if the media player is in a state different from PAUSED, READY or PLAYING state.

seek

public void seek(long position)
          throws IllegalStateException
Description copied from interface: MediaPlayer
Moves the play head to specified position. The actual start position after seek may be different than the desired one due additional rules which may apply. For example seeking in the middle of an ad is not permitted and in this case the seek position will be adjusted to the beginning of the ad. Live playback accepts the usage of constant LIVE_POINT. Passing this as a position will make a seek operation to the client live point contained in the live window. As a reference, the client live point moves in time and it should be situated at the end of the live window - buffer length - 3 * target duration. Using the LIVE_POINT for video on demand content will cause the player to readjust the position to the beginning of the content. Given a desired seek position that is not included in the seekable range will cause the desired seek position to be readjusted to the nearest limit of the seekable range (either beginning or end) Developers should listen for SEEK_COMPLETE notification which will provide the adjusted position.

Specified by:
seek in interface MediaPlayer
Parameters:
position - the desired position from where to start the playback
Throws:
IllegalStateException - if the media player is in a state different from PAUSED, READY or PLAYING state.

reset

public void reset()
           throws IllegalStateException
Description copied from interface: MediaPlayer
Resets the media player to its uninitialized state. After calling this method, you will have to initialize it again by setting the media player item through replaceCurrentItem() method and calling prepareToPlay() method.

Specified by:
reset in interface MediaPlayer
Throws:
IllegalStateException - if the media player was already released.

release

public void release()
             throws IllegalStateException
Description copied from interface: MediaPlayer
Releases media player object. IMPORTANT! The media player being released can't be used anymore. Invoking any method of the media player once has been released will result in an IllegalStateException being thrown. It will release the underlying resources associated with this media player object. It is considered good practice to call this method when you're done using it. In addition to unnecessary resources being held, failure to call this method immediately if a media player object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device.

Specified by:
release in interface MediaPlayer
Throws:
IllegalStateException

replaceCurrentItem

public void replaceCurrentItem(MediaResource resource)
                        throws IllegalStateException
Description copied from interface: MediaPlayer
Replaces the current media item or sets one if none exists. Use this method to specify the media to be played. The media resource contains information about the stream URL to be played alongside metadata (such as ad breaks information). The prepareToPlay() should be called afterwards.

Specified by:
replaceCurrentItem in interface MediaPlayer
Parameters:
resource - the media resource to be set
Throws:
IllegalStateException - if the media player was already released.

getCurrentItem

public MediaPlayerItem getCurrentItem()
                               throws IllegalStateException
Description copied from interface: MediaPlayer
Gets the current media player item.

Specified by:
getCurrentItem in interface MediaPlayer
Returns:
the media player item which can be used for querying or changing media characteristics.
Throws:
IllegalStateException - if the media player item is not yet available or the media player was already released.

getPlaybackRange

public TimeRange getPlaybackRange()
                           throws IllegalStateException
Specified by:
getPlaybackRange in interface MediaPlayer
Returns:
the actual playback range of the stream or an empty range if stream is not yet processed. This range includes also the duration of any additional content inserted into the stream (ads).
Throws:
IllegalStateException - if media player was already released.

getSeekableRange

public TimeRange getSeekableRange()
                           throws IllegalStateException
Description copied from interface: MediaPlayer
Returns the seekable range

Specified by:
getSeekableRange in interface MediaPlayer
Returns:
the actual seekable range of the stream or an empty range if stream is not yet processed. Seeking should be performed only to a position inside this range. This range includes also the duration of any additional content inserted into the stream (ads).
Throws:
IllegalStateException - IllegalStateException if media player was already released.

getCurrentTime

public long getCurrentTime()
                    throws IllegalStateException
Description copied from interface: MediaPlayer
The current playhead time as reported by the underlying components. The playhead time is calculated relative to the resolved stream, one which can contain multiple ads inserted.

Specified by:
getCurrentTime in interface MediaPlayer
Returns:
the current playhead position or 0 if not available.
Throws:
IllegalStateException - if the media player was already released.

getBufferedRange

public TimeRange getBufferedRange()
                           throws IllegalStateException
Description copied from interface: MediaPlayer
Returns the buffered range.

Specified by:
getBufferedRange in interface MediaPlayer
Returns:
a time range indicating the period already buffered locally.
Throws:
IllegalStateException - if the media player was already released.

getTimeline

public Timeline getTimeline()
                     throws IllegalStateException
Description copied from interface: MediaPlayer
The current timeline containing both main content and associated alternate content (ads). The timeline can update over time as more and more alternate content is placed on it.

Specified by:
getTimeline in interface MediaPlayer
Returns:
the current timeline interface which can be used to iterate through timeline items.
Throws:
IllegalStateException - if the media player was already released.

getStatus

public MediaPlayer.PlayerState getStatus()
                                  throws IllegalStateException
Description copied from interface: MediaPlayer
Returns the media player status.

Specified by:
getStatus in interface MediaPlayer
Returns:
the current status of the media player.
Throws:
IllegalStateException - if media player was already released.

addEventListener

public void addEventListener(MediaPlayer.Event event,
                             MediaPlayer.EventListener listener)
Description copied from interface: MediaPlayer
Adds a new event listener for specified event type.

Specified by:
addEventListener in interface MediaPlayer
Parameters:
event - the type of events we want to monitor
listener - the listener which will be used when the specified event happened

removeEventListener

public void removeEventListener(MediaPlayer.Event event,
                                MediaPlayer.EventListener listener)
Description copied from interface: MediaPlayer
Removes an existing event listener for specified event type.

Specified by:
removeEventListener in interface MediaPlayer
Parameters:
event - the type of events we want to monitor
listener - the listener which will be used when the specified event happened

setVolume

public void setVolume(int volume)
Description copied from interface: MediaPlayer
Change the media player volume. Ranges from 0 (silent) to 100 (full volume).

Specified by:
setVolume in interface MediaPlayer
Parameters:
volume - the desired volume value to be set.

setABRControlParameters

public void setABRControlParameters(ABRControlParameters params)
                             throws IllegalStateException
Description copied from interface: MediaPlayer
Set the parameters that control the playback of MBR content.

Specified by:
setABRControlParameters in interface MediaPlayer
Parameters:
params - instance of the ABRControlParameters containing the MBR control parameters.
Throws:
IllegalStateException - if media player was already released.

setBufferControlParameters

public void setBufferControlParameters(BufferControlParameters params)
                                throws IllegalStateException
Description copied from interface: MediaPlayer
Set the parameters that control the media player buffer.

Specified by:
setBufferControlParameters in interface MediaPlayer
Parameters:
params - instance of the BufferControlParameters, containing the initial buffer time and the player buffer time.
Throws:
IllegalStateException - if media player was already released.

getBufferControlParameters

public BufferControlParameters getBufferControlParameters()
                                                   throws IllegalStateException
Specified by:
getBufferControlParameters in interface MediaPlayer
Returns:
the current buffer control parameters, containing the initial buffer time and the player buffer time.
Throws:
IllegalStateException - if media player was already released.

getCCVisibility

public MediaPlayer.Visibility getCCVisibility()
                                       throws IllegalStateException
Specified by:
getCCVisibility in interface MediaPlayer
Returns:
the current status of closed captions visibility. VISIBLE if closed captions should be displayed when available, or INVISIBLE if otherwise.
Throws:
IllegalStateException - if media player was already released.

setCCVisibility

public void setCCVisibility(MediaPlayer.Visibility visibility)
                     throws IllegalStateException
Description copied from interface: MediaPlayer
Sets the visibility of closed captioning. This method is safe to use even if the current media stream doesn't have closed captions.

Specified by:
setCCVisibility in interface MediaPlayer
Parameters:
visibility - setting this to VISIBLE it will trigger the display of closed captions if available, setting this to INVISIBLE if will hide the close captions.
Throws:
IllegalStateException - if the media player was already released.

setCCStyle

public void setCCStyle(TextFormat textFormat)
                throws IllegalStateException
Description copied from interface: MediaPlayer
Sets the closed captioning style. Used to control the closed captioning font, size, color, edge and opacity. This method is safe to use even if the current media stream doesn't have closed captions.

Specified by:
setCCStyle in interface MediaPlayer
Parameters:
textFormat - TextFormat to be used
Throws:
IllegalStateException

getCCStyle

public TextFormat getCCStyle()
                      throws IllegalStateException
Specified by:
getCCStyle in interface MediaPlayer
Returns:
the current closed captioning style. If no style was previously set, it returns a TextFormat object with default values for each attribute.
Throws:
IllegalStateException - if media player was already released.

getDRMManager

public DRMManager getDRMManager()
                         throws IllegalStateException
Specified by:
getDRMManager in interface MediaPlayer
Returns:
returns the DRM manager associated with this player instance.
Throws:
IllegalStateException

getPlaybackMetrics

public PlaybackMetrics getPlaybackMetrics()
                                   throws IllegalStateException
Specified by:
getPlaybackMetrics in interface MediaPlayer
Returns:
playback metrics
Throws:
IllegalStateException - if media player was already released.

getNotificationHistory

public NotificationHistory getNotificationHistory()
Specified by:
getNotificationHistory in interface MediaPlayer
Returns:
notification history object

getView

public MediaPlayerView getView()
Description copied from interface: MediaPlayer
Returns the view where the media player will render the images.

Specified by:
getView in interface MediaPlayer
Returns:
the media player view which can be positioned and scaled

registerAdClientFactory

public void registerAdClientFactory(AdClientFactory adClientFactory)
Description copied from interface: MediaPlayer
Sets a custom AdvertisingFactory to be used in the ad placement process. This factory can create a custom ad provider, to be used in the ad resolving. It can also set a custom ad opportunity detector, that iterates through the timed metadata and creates a list of PlacementOpportunity. This opportunities will be resolved by the ad provider.

Specified by:
registerAdClientFactory in interface MediaPlayer
Parameters:
adClientFactory - the custom ad client factory.

setStatus

protected void setStatus(MediaPlayer.PlayerState state,
                         MediaPlayerNotification.Error error)