15
15
*/
16
16
package androidx .media3 .exoplayer .source ;
17
17
18
+ import static androidx .media3 .common .util .Assertions .checkArgument ;
19
+ import static androidx .media3 .common .util .Assertions .checkState ;
18
20
import static com .google .common .truth .Truth .assertThat ;
19
21
20
22
import androidx .media3 .common .C ;
@@ -29,7 +31,8 @@ public final class CompositeSequenceableLoaderTest {
29
31
30
32
/**
31
33
* Tests that {@link CompositeSequenceableLoader#getBufferedPositionUs()} returns minimum buffered
32
- * position among all sub-loaders.
34
+ * position among all sub-loaders, and is consistent with {@link
35
+ * CompositeSequenceableLoader#isLoading()}.
33
36
*/
34
37
@ Test
35
38
public void getBufferedPositionUsReturnsMinimumLoaderBufferedPosition () {
@@ -40,11 +43,13 @@ public void getBufferedPositionUsReturnsMinimumLoaderBufferedPosition() {
40
43
CompositeSequenceableLoader compositeSequenceableLoader =
41
44
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 });
42
45
assertThat (compositeSequenceableLoader .getBufferedPositionUs ()).isEqualTo (1000 );
46
+ assertThat (compositeSequenceableLoader .isLoading ()).isTrue ();
43
47
}
44
48
45
49
/**
46
50
* Tests that {@link CompositeSequenceableLoader#getBufferedPositionUs()} returns minimum buffered
47
- * position that is not {@link C#TIME_END_OF_SOURCE} among all sub-loaders.
51
+ * position that is not {@link C#TIME_END_OF_SOURCE} among all sub-loaders, and is consistent with
52
+ * {@link CompositeSequenceableLoader#isLoading()}.
48
53
*/
49
54
@ Test
50
55
public void getBufferedPositionUsReturnsMinimumNonEndOfSourceLoaderBufferedPosition () {
@@ -59,11 +64,13 @@ public void getBufferedPositionUsReturnsMinimumNonEndOfSourceLoaderBufferedPosit
59
64
CompositeSequenceableLoader compositeSequenceableLoader =
60
65
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 , loader3 });
61
66
assertThat (compositeSequenceableLoader .getBufferedPositionUs ()).isEqualTo (1000 );
67
+ assertThat (compositeSequenceableLoader .isLoading ()).isTrue ();
62
68
}
63
69
64
70
/**
65
71
* Tests that {@link CompositeSequenceableLoader#getBufferedPositionUs()} returns {@link
66
- * C#TIME_END_OF_SOURCE} when all sub-loaders have buffered till end-of-source.
72
+ * C#TIME_END_OF_SOURCE} when all sub-loaders have buffered till end-of-source, and is consistent
73
+ * with {@link CompositeSequenceableLoader#isLoading()}.
67
74
*/
68
75
@ Test
69
76
public void getBufferedPositionUsReturnsEndOfSourceWhenAllLoaderBufferedTillEndOfSource () {
@@ -78,11 +85,13 @@ public void getBufferedPositionUsReturnsEndOfSourceWhenAllLoaderBufferedTillEndO
78
85
CompositeSequenceableLoader compositeSequenceableLoader =
79
86
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 });
80
87
assertThat (compositeSequenceableLoader .getBufferedPositionUs ()).isEqualTo (C .TIME_END_OF_SOURCE );
88
+ assertThat (compositeSequenceableLoader .isLoading ()).isFalse ();
81
89
}
82
90
83
91
/**
84
92
* Tests that {@link CompositeSequenceableLoader#getNextLoadPositionUs()} returns minimum next
85
- * load position among all sub-loaders.
93
+ * load position among all sub-loaders, and is consistent with {@link
94
+ * CompositeSequenceableLoader#isLoading()}.
86
95
*/
87
96
@ Test
88
97
public void getNextLoadPositionUsReturnMinimumLoaderNextLoadPositionUs () {
@@ -93,11 +102,13 @@ public void getNextLoadPositionUsReturnMinimumLoaderNextLoadPositionUs() {
93
102
CompositeSequenceableLoader compositeSequenceableLoader =
94
103
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 });
95
104
assertThat (compositeSequenceableLoader .getNextLoadPositionUs ()).isEqualTo (2000 );
105
+ assertThat (compositeSequenceableLoader .isLoading ()).isTrue ();
96
106
}
97
107
98
108
/**
99
109
* Tests that {@link CompositeSequenceableLoader#getNextLoadPositionUs()} returns minimum next
100
- * load position that is not {@link C#TIME_END_OF_SOURCE} among all sub-loaders.
110
+ * load position that is not {@link C#TIME_END_OF_SOURCE} among all sub-loaders, and is consistent
111
+ * with {@link CompositeSequenceableLoader#isLoading()}.
101
112
*/
102
113
@ Test
103
114
public void getNextLoadPositionUsReturnMinimumNonEndOfSourceLoaderNextLoadPositionUs () {
@@ -111,11 +122,13 @@ public void getNextLoadPositionUsReturnMinimumNonEndOfSourceLoaderNextLoadPositi
111
122
CompositeSequenceableLoader compositeSequenceableLoader =
112
123
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 , loader3 });
113
124
assertThat (compositeSequenceableLoader .getNextLoadPositionUs ()).isEqualTo (2000 );
125
+ assertThat (compositeSequenceableLoader .isLoading ()).isTrue ();
114
126
}
115
127
116
128
/**
117
129
* Tests that {@link CompositeSequenceableLoader#getNextLoadPositionUs()} returns {@link
118
- * C#TIME_END_OF_SOURCE} when all sub-loaders have next load position at end-of-source.
130
+ * C#TIME_END_OF_SOURCE} when all sub-loaders have next load position at end-of-source, and is
131
+ * consistent with {@link CompositeSequenceableLoader#isLoading()}.
119
132
*/
120
133
@ Test
121
134
public void getNextLoadPositionUsReturnsEndOfSourceWhenAllLoaderLoadingLastChunk () {
@@ -128,6 +141,7 @@ public void getNextLoadPositionUsReturnsEndOfSourceWhenAllLoaderLoadingLastChunk
128
141
CompositeSequenceableLoader compositeSequenceableLoader =
129
142
new CompositeSequenceableLoader (new SequenceableLoader [] {loader1 , loader2 });
130
143
assertThat (compositeSequenceableLoader .getNextLoadPositionUs ()).isEqualTo (C .TIME_END_OF_SOURCE );
144
+ assertThat (compositeSequenceableLoader .isLoading ()).isFalse ();
131
145
}
132
146
133
147
/**
@@ -246,6 +260,9 @@ private static class FakeSequenceableLoader implements SequenceableLoader {
246
260
private int nextChunkDurationUs ;
247
261
248
262
private FakeSequenceableLoader (long bufferedPositionUs , long nextLoadPositionUs ) {
263
+ if (bufferedPositionUs == C .TIME_END_OF_SOURCE ) {
264
+ checkArgument (nextLoadPositionUs == C .TIME_END_OF_SOURCE );
265
+ }
249
266
this .bufferedPositionUs = bufferedPositionUs ;
250
267
this .nextLoadPositionUs = nextLoadPositionUs ;
251
268
}
@@ -263,17 +280,22 @@ public long getNextLoadPositionUs() {
263
280
@ Override
264
281
public boolean continueLoading (LoadingInfo loadingInfo ) {
265
282
numInvocations ++;
266
- boolean loaded = nextChunkDurationUs != 0 ;
267
- // The current chunk has been loaded, advance to next chunk.
283
+
268
284
bufferedPositionUs = nextLoadPositionUs ;
285
+ if (nextLoadPositionUs == C .TIME_END_OF_SOURCE ) {
286
+ return false ;
287
+ }
288
+
289
+ long oldNextLoadPositionUs = nextLoadPositionUs ;
290
+ // The current chunk has been loaded, advance to next chunk.
269
291
nextLoadPositionUs += nextChunkDurationUs ;
270
292
nextChunkDurationUs = 0 ;
271
- return loaded ;
293
+ return oldNextLoadPositionUs != nextLoadPositionUs ;
272
294
}
273
295
274
296
@ Override
275
297
public boolean isLoading () {
276
- return nextChunkDurationUs != 0 ;
298
+ return nextLoadPositionUs != C . TIME_END_OF_SOURCE ;
277
299
}
278
300
279
301
@ Override
@@ -282,6 +304,7 @@ public void reevaluateBuffer(long positionUs) {
282
304
}
283
305
284
306
private void setNextChunkDurationUs (int nextChunkDurationUs ) {
307
+ checkState (nextLoadPositionUs != C .TIME_END_OF_SOURCE );
285
308
this .nextChunkDurationUs = nextChunkDurationUs ;
286
309
}
287
310
}
0 commit comments