• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 package com.google.android.exoplayer2.source;
17 
18 import com.google.android.exoplayer2.C;
19 
20 // TODO: Clarify the requirements for implementing this interface [Internal ref: b/36250203].
21 /**
22  * A loader that can proceed in approximate synchronization with other loaders.
23  */
24 public interface SequenceableLoader {
25 
26   /**
27    * A callback to be notified of {@link SequenceableLoader} events.
28    */
29   interface Callback<T extends SequenceableLoader> {
30 
31     /**
32      * Called by the loader to indicate that it wishes for its {@link #continueLoading(long)} method
33      * to be called when it can continue to load data. Called on the playback thread.
34      */
onContinueLoadingRequested(T source)35     void onContinueLoadingRequested(T source);
36 
37   }
38 
39   /**
40    * Returns an estimate of the position up to which data is buffered.
41    *
42    * @return An estimate of the absolute position in microseconds up to which data is buffered, or
43    *     {@link C#TIME_END_OF_SOURCE} if the data is fully buffered.
44    */
getBufferedPositionUs()45   long getBufferedPositionUs();
46 
47   /**
48    * Returns the next load time, or {@link C#TIME_END_OF_SOURCE} if loading has finished.
49    */
getNextLoadPositionUs()50   long getNextLoadPositionUs();
51 
52   /**
53    * Attempts to continue loading.
54    *
55    * @param positionUs The current playback position in microseconds. If playback of the period to
56    *     which this loader belongs has not yet started, the value will be the starting position
57    *     in the period minus the duration of any media in previous periods still to be played.
58    * @return True if progress was made, meaning that {@link #getNextLoadPositionUs()} will return
59    *     a different value than prior to the call. False otherwise.
60    */
continueLoading(long positionUs)61   boolean continueLoading(long positionUs);
62 
63   /** Returns whether the loader is currently loading. */
isLoading()64   boolean isLoading();
65 
66   /**
67    * Re-evaluates the buffer given the playback position.
68    *
69    * <p>Re-evaluation may discard buffered media so that it can be re-buffered in a different
70    * quality.
71    *
72    * @param positionUs The current playback position in microseconds. If playback of this period has
73    *     not yet started, the value will be the starting position in this period minus the duration
74    *     of any media in previous periods still to be played.
75    */
reevaluateBuffer(long positionUs)76   void reevaluateBuffer(long positionUs);
77 }
78