1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.media.subtitle; 18 19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20 21 import androidx.annotation.RestrictTo; 22 23 // Note: This is just copied from android.media.MediaTimeProvider. 24 /** 25 * @hide 26 */ 27 @RestrictTo(LIBRARY_GROUP) 28 public interface MediaTimeProvider { 29 // we do not allow negative media time 30 /** 31 * Presentation time value if no timed event notification is requested. 32 */ 33 long NO_TIME = -1; 34 35 /** 36 * Cancels all previous notification request from this listener if any. It 37 * registers the listener to get seek and stop notifications. If timeUs is 38 * not negative, it also registers the listener for a timed event 39 * notification when the presentation time reaches (becomes greater) than 40 * the value specified. This happens immediately if the current media time 41 * is larger than or equal to timeUs. 42 * 43 * @param timeUs presentation time to get timed event callback at (or 44 * {@link #NO_TIME}) 45 */ 46 void notifyAt(long timeUs, OnMediaTimeListener listener); 47 48 /** 49 * Cancels all previous notification request from this listener if any. It 50 * registers the listener to get seek and stop notifications. If the media 51 * is stopped, the listener will immediately receive a stop notification. 52 * Otherwise, it will receive a timed event notificaton. 53 */ 54 void scheduleUpdate(OnMediaTimeListener listener); 55 56 /** 57 * Cancels all previous notification request from this listener if any. 58 */ 59 void cancelNotifications(OnMediaTimeListener listener); 60 61 /** 62 * Get the current presentation time. 63 * 64 * @param precise Whether getting a precise time is important. This is 65 * more costly. 66 * @param monotonic Whether returned time should be monotonic: that is, 67 * greater than or equal to the last returned time. Don't 68 * always set this to true. E.g. this has undesired 69 * consequences if the media is seeked between calls. 70 * @throws IllegalStateException if the media is not initialized 71 */ 72 long getCurrentTimeUs(boolean precise, boolean monotonic) 73 throws IllegalStateException; 74 75 /** 76 * Mediatime listener 77 */ 78 public interface OnMediaTimeListener { 79 /** 80 * Called when the registered time was reached naturally. 81 * 82 * @param timeUs current media time 83 */ 84 void onTimedEvent(long timeUs); 85 86 /** 87 * Called when the media time changed due to seeking. 88 * 89 * @param timeUs current media time 90 */ 91 void onSeek(long timeUs); 92 93 /** 94 * Called when the playback stopped. This is not called on pause, only 95 * on full stop, at which point there is no further current media time. 96 */ 97 void onStop(); 98 } 99 } 100 101