Class ShadowMediaPlayer.MediaInfo

java.lang.Object
org.robolectric.shadows.ShadowMediaPlayer.MediaInfo
Enclosing class:
ShadowMediaPlayer

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.
  • Field Details

    • duration

      public int duration
    • events

      public TreeMap<Integer,org.robolectric.shadows.ShadowMediaPlayer.RunList> events
      Map that maps time offsets to media events.
  • Constructor Details

    • MediaInfo

      public MediaInfo()
      Creates a new MediaInfo object with default duration (1000ms) and default preparation delay (0ms).
    • MediaInfo

      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.
      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, then ShadowMediaPlayer.prepare() will complete instantly but ShadowMediaPlayer.prepareAsync() will not complete automatically; you will need to call ShadowMediaPlayer.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

      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.
      Parameters:
      offset - the offset from the start of playback at which this event will run.
      event - the event to run.
    • scheduleErrorAtOffset

      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).
      Parameters:
      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().
      Returns:
      A reference to the MediaEvent object that was created and scheduled.
    • scheduleInfoAtOffset

      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).
      Parameters:
      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().
      Returns:
      A reference to the MediaEvent object that was created and scheduled.
    • scheduleBufferUnderrunAtOffset

      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.

      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

      public void removeEventAtOffset(int offset, ShadowMediaPlayer.MediaEvent event)
      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

      public void removeEvent(ShadowMediaPlayer.MediaEvent event)
      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: