Package org.robolectric.shadows
Class ShadowMediaPlayer.MediaInfo
java.lang.Object
org.robolectric.shadows.ShadowMediaPlayer.MediaInfo
- Enclosing class:
- ShadowMediaPlayer
Class specifying information for an emulated media object. Used by ShadowMediaPlayer when
setDataSource() is called to populate the shadow player with the specified values.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves the current preparation delay for this media.void
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.scheduleBufferUnderrunAtOffset
(int offset, int length) Schedules a simulated buffer underrun event to run at the specified playback offset.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.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.
-
Field Details
-
duration
public int duration -
events
Map that maps time offsets to media events.
-
-
Constructor Details
-
MediaInfo
public MediaInfo()Creates a newMediaInfo
object with default duration (1000ms) and default preparation delay (0ms). -
MediaInfo
public MediaInfo(int duration, int preparationDelay) Creates a newMediaInfo
object with the given duration and preparation delay. A completion callback event is scheduled atduration
ms from the end.- Parameters:
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, thenShadowMediaPlayer.prepare()
will complete instantly butShadowMediaPlayer.prepareAsync()
will not complete automatically; you will need to callShadowMediaPlayer.invokePreparedListener()
manually.
-
-
Method Details
-
getPreparationDelay
public int getPreparationDelay()Retrieves the current preparation delay for this media.- Returns:
- The current preparation delay (in ms).
-
setPreparationDelay
public void setPreparationDelay(int preparationDelay) Sets the current preparation delay for this media.- Parameters:
preparationDelay
- the new preparation delay (in ms).
-
scheduleEventAtOffset
Schedules a generic event to run at the specified playback offset. Events are run on the thread on which theMediaPlayer
was created.- Parameters:
offset
- the offset from the start of playback at which this event will run.event
- the event to run.
-
scheduleErrorAtOffset
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 toremoveEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.- Parameters:
offset
- the offset from the start of playback at which this error will trigger.what
- the value for thewhat
parameter to use in the call toonError()
.extra
- the value for theextra
parameter to use in the call toonError()
.- Returns:
- A reference to the MediaEvent object that was created and scheduled.
-
scheduleInfoAtOffset
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 toremoveEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.- Parameters:
offset
- the offset from the start of playback at which this event will trigger.what
- the value for thewhat
parameter to use in the call toonInfo()
.extra
- the value for theextra
parameter to use in the call toonInfo()
.- Returns:
- A reference to the MediaEvent object that was created and scheduled.
-
scheduleBufferUnderrunAtOffset
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 toremoveEventAtOffset(int, org.robolectric.shadows.ShadowMediaPlayer.MediaEvent)
.This event will issue an
onInfo()
callback withMediaPlayer.MEDIA_INFO_BUFFERING_START
to signal the start of buffering and then callShadowMediaPlayer.doStop()
to internally pause playback. Finally it will schedule an event to fire afterlength
ms which fires aMediaPlayer.MEDIA_INFO_BUFFERING_END
info event and invokesShadowMediaPlayer.doStart()
to resume playback.- Parameters:
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.- Returns:
- A reference to the MediaEvent object that was created and scheduled.
-
removeEventAtOffset
Removes the specified event from the playback schedule at the given playback offset.- Parameters:
offset
- the offset at which the event was scheduled.event
- the event to remove.- See Also:
-
removeEvent
Removes the specified event from the playback schedule at all playback offsets where it has been scheduled.- Parameters:
event
- the event to remove.- See Also:
-