Class 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 Detail

      • duration

        public int duration
      • events

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

      • 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 Detail

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