public static class ShadowMediaPlayer.MediaInfo extends Object
Class specifying information for an emulated media object. Used by ShadowMediaPlayer when setDataSource() is called to populate the shadow player with the specified values.
Modifier and Type | Field and Description |
---|---|
int |
duration |
TreeMap<Integer,org.robolectric.shadows.ShadowMediaPlayer.RunList> |
events
Map that maps time offsets to media events.
|
Constructor and Description |
---|
MediaInfo()
Creates a new
MediaInfo object with default duration (1000ms) and default preparation delay (0ms). |
MediaInfo(int duration,
int preparationDelay)
Creates a new
MediaInfo object with the given duration and preparation delay. |
Modifier and Type | Method and Description |
---|---|
int |
getPreparationDelay()
Retrieves the current preparation delay for this media.
|
void |
removeEvent(ShadowMediaPlayer.MediaEvent event)
Removes the specified event from the playback schedule at all playback offsets where it has been scheduled.
|
void |
removeEventAtOffset(int offset,
ShadowMediaPlayer.MediaEvent event)
Removes the specified event from the playback schedule at the given playback offset.
|
ShadowMediaPlayer.MediaEvent |
scheduleBufferUnderrunAtOffset(int offset,
int length)
Schedules a simulated buffer underrun event to run at the specified playback offset.
|
ShadowMediaPlayer.MediaEvent |
scheduleErrorAtOffset(int offset,
int what,
int extra)
Schedules an error event to run at the specified playback offset.
|
void |
scheduleEventAtOffset(int offset,
ShadowMediaPlayer.MediaEvent event)
Schedules a generic event to run at the specified playback offset.
|
ShadowMediaPlayer.MediaEvent |
scheduleInfoAtOffset(int offset,
int what,
int extra)
Schedules an info event to run at the specified playback offset.
|
void |
setPreparationDelay(int preparationDelay)
Sets the current preparation delay for this media.
|
public MediaInfo()
Creates a new MediaInfo
object with default duration (1000ms) and default preparation delay (0ms).
public MediaInfo(int duration, int preparationDelay)
Creates a new MediaInfo
object with the given duration and preparation delay. A completion callback event is scheduled at duration
ms from the end.
duration
- the duration (in ms) of this emulated media. A callback event will be scheduled at this offset to stop playback simulation and invoke the completion callback.preparationDelay
- the preparation delay (in ms) to emulate for this media. If set to -1, then ShadowMediaPlayer.prepare()
will complete instantly but ShadowMediaPlayer.prepareAsync()
will not complete automatically; you will need to call ShadowMediaPlayer.invokePreparedListener()
manually.public int getPreparationDelay()
Retrieves the current preparation delay for this media.
public void setPreparationDelay(int preparationDelay)
Sets the current preparation delay for this media.
preparationDelay
- the new preparation delay (in ms).public void scheduleEventAtOffset(int offset, ShadowMediaPlayer.MediaEvent event)
Schedules a generic event to run at the specified playback offset. Events are run on the thread on which the MediaPlayer
was created.
offset
- the offset from the start of playback at which this event will run.event
- the event to run.public ShadowMediaPlayer.MediaEvent scheduleErrorAtOffset(int offset, int what, int extra)
Schedules an error event to run at the specified playback offset. A reference to the actual MediaEvent that is scheduled is returned, which can be used in a subsequent call to removeEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.
offset
- the offset from the start of playback at which this error will trigger.what
- the value for the what
parameter to use in the call to onError()
.extra
- the value for the extra
parameter to use in the call to onError()
.public ShadowMediaPlayer.MediaEvent scheduleInfoAtOffset(int offset, int what, int extra)
Schedules an info event to run at the specified playback offset. A reference to the actual MediaEvent that is scheduled is returned, which can be used in a subsequent call to removeEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.
offset
- the offset from the start of playback at which this event will trigger.what
- the value for the what
parameter to use in the call to onInfo()
.extra
- the value for the extra
parameter to use in the call to onInfo()
.public ShadowMediaPlayer.MediaEvent scheduleBufferUnderrunAtOffset(int offset, int length)
Schedules a simulated buffer underrun event to run at the specified playback offset. A reference to the actual MediaEvent that is scheduled is returned, which can be used in a subsequent call to removeEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.
This event will issue an onInfo()
callback with MediaPlayer.MEDIA_INFO_BUFFERING_START
to signal the start of buffering and then call ShadowMediaPlayer.doStop()
to internally pause playback. Finally it will schedule an event to fire after length
ms which fires a MediaPlayer.MEDIA_INFO_BUFFERING_END
info event and invokes ShadowMediaPlayer.doStart()
to resume playback.
offset
- the offset from the start of playback at which this underrun will trigger.length
- the length of time (in ms) for which playback will be paused.public void removeEventAtOffset(int offset, ShadowMediaPlayer.MediaEvent event)
Removes the specified event from the playback schedule at the given playback offset.
offset
- the offset at which the event was scheduled.event
- the event to remove.removeEvent(ShadowMediaPlayer.MediaEvent)
public void removeEvent(ShadowMediaPlayer.MediaEvent event)
Removes the specified event from the playback schedule at all playback offsets where it has been scheduled.
event
- the event to remove.removeEventAtOffset(int,ShadowMediaPlayer.MediaEvent)