mirror of
https://github.com/samsonjs/media.git
synced 2026-04-16 13:05:46 +00:00
Initialize sample streams in FakeAdaptiveMediaPeriod.
This prevents NPE when release or stop is called before tracks have been selected. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=179911907
This commit is contained in:
parent
ec71c05e8b
commit
7fb296dab9
1 changed files with 13 additions and 5 deletions
|
|
@ -44,13 +44,18 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
|||
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
|
||||
private SequenceableLoader sequenceableLoader;
|
||||
|
||||
public FakeAdaptiveMediaPeriod(TrackGroupArray trackGroupArray, EventDispatcher eventDispatcher,
|
||||
Allocator allocator, FakeChunkSource.Factory chunkSourceFactory, long durationUs) {
|
||||
public FakeAdaptiveMediaPeriod(
|
||||
TrackGroupArray trackGroupArray,
|
||||
EventDispatcher eventDispatcher,
|
||||
Allocator allocator,
|
||||
FakeChunkSource.Factory chunkSourceFactory,
|
||||
long durationUs) {
|
||||
super(trackGroupArray);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.allocator = allocator;
|
||||
this.chunkSourceFactory = chunkSourceFactory;
|
||||
this.durationUs = durationUs;
|
||||
this.sampleStreams = newSampleStreamArray(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -62,13 +67,12 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
public synchronized void prepare(Callback callback, long positionUs) {
|
||||
super.prepare(callback, positionUs);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
||||
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
||||
long returnPositionUs = super.selectTracks(selections, mayRetainStreamFlags, streams,
|
||||
|
|
@ -79,7 +83,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
|||
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
|
||||
}
|
||||
}
|
||||
this.sampleStreams = validStreams.toArray(new ChunkSampleStream[validStreams.size()]);
|
||||
this.sampleStreams = validStreams.toArray(newSampleStreamArray(validStreams.size()));
|
||||
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
|
||||
return returnPositionUs;
|
||||
}
|
||||
|
|
@ -131,4 +135,8 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
|||
callback.onContinueLoadingRequested(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static ChunkSampleStream<FakeChunkSource>[] newSampleStreamArray(int length) {
|
||||
return new ChunkSampleStream[length];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue