public interface

MediaTimeProvider

 androidx.media2.subtitle.MediaTimeProvider

Gradle dependencies

compile group: 'androidx.media2', name: 'media2', version: '1.0.0-alpha04'

  • groupId: androidx.media2
  • artifactId: media2
  • version: 1.0.0-alpha04

Artifact androidx.media2:media2:1.0.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.media2:media2 com.android.support:media2

Summary

Fields
public static final longNO_TIME

Presentation time value if no timed event notification is requested.

Methods
public voidcancelNotifications(MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any.

public longgetCurrentTimeUs(boolean precise, boolean monotonic)

Get the current presentation time.

public voidnotifyAt(long timeUs, MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any.

public voidscheduleUpdate(MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any.

Fields

public static final long NO_TIME

Presentation time value if no timed event notification is requested.

Methods

public void notifyAt(long timeUs, MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any. It registers the listener to get seek and stop notifications. If timeUs is not negative, it also registers the listener for a timed event notification when the presentation time reaches (becomes greater) than the value specified. This happens immediately if the current media time is larger than or equal to timeUs.

Parameters:

timeUs: presentation time to get timed event callback at (or MediaTimeProvider.NO_TIME)

public void scheduleUpdate(MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any. It registers the listener to get seek and stop notifications. If the media is stopped, the listener will immediately receive a stop notification. Otherwise, it will receive a timed event notificaton.

public void cancelNotifications(MediaTimeProvider.OnMediaTimeListener listener)

Cancels all previous notification request from this listener if any.

public long getCurrentTimeUs(boolean precise, boolean monotonic)

Get the current presentation time.

Parameters:

precise: Whether getting a precise time is important. This is more costly.
monotonic: Whether returned time should be monotonic: that is, greater than or equal to the last returned time. Don't always set this to true. E.g. this has undesired consequences if the media is seeked between calls.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media2.subtitle;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.RestrictTo;

// Note: This is just copied from android.media.MediaTimeProvider.
/**
 * @hide
 */
@RestrictTo(LIBRARY_GROUP)
public interface MediaTimeProvider {
    // we do not allow negative media time
    /**
     * Presentation time value if no timed event notification is requested.
     */
    long NO_TIME = -1;

    /**
     * Cancels all previous notification request from this listener if any.  It
     * registers the listener to get seek and stop notifications.  If timeUs is
     * not negative, it also registers the listener for a timed event
     * notification when the presentation time reaches (becomes greater) than
     * the value specified.  This happens immediately if the current media time
     * is larger than or equal to timeUs.
     *
     * @param timeUs presentation time to get timed event callback at (or
     *               {@link #NO_TIME})
     */
    void notifyAt(long timeUs, OnMediaTimeListener listener);

    /**
     * Cancels all previous notification request from this listener if any.  It
     * registers the listener to get seek and stop notifications.  If the media
     * is stopped, the listener will immediately receive a stop notification.
     * Otherwise, it will receive a timed event notificaton.
     */
    void scheduleUpdate(OnMediaTimeListener listener);

    /**
     * Cancels all previous notification request from this listener if any.
     */
    void cancelNotifications(OnMediaTimeListener listener);

    /**
     * Get the current presentation time.
     *
     * @param precise   Whether getting a precise time is important. This is
     *                  more costly.
     * @param monotonic Whether returned time should be monotonic: that is,
     *                  greater than or equal to the last returned time.  Don't
     *                  always set this to true.  E.g. this has undesired
     *                  consequences if the media is seeked between calls.
     * @throws IllegalStateException if the media is not initialized
     */
    long getCurrentTimeUs(boolean precise, boolean monotonic)
            throws IllegalStateException;

    /**
     * Mediatime listener
     */
    public interface OnMediaTimeListener {
        /**
         * Called when the registered time was reached naturally.
         *
         * @param timeUs current media time
         */
        void onTimedEvent(long timeUs);

        /**
         * Called when the media time changed due to seeking.
         *
         * @param timeUs current media time
         */
        void onSeek(long timeUs);

        /**
         * Called when the playback stopped.  This is not called on pause, only
         * on full stop, at which point there is no further current media time.
         */
        void onStop();
    }
}