@Override public void onLoadCanceled(Loadable loadable) { if (enabledTrackCount > 0) { restartFrom(pendingResetPositionUs); } else { clearState(); allocator.trim(0); } }
@Override public void enable(int track, long positionUs) { Assertions.checkState(prepared); Assertions.checkState(!trackEnabledStates[track]); enabledTrackCount++; trackEnabledStates[track] = true; pendingMediaFormat[track] = true; pendingDiscontinuities[track] = false; if (enabledTrackCount == 1) { // Treat all enables in non-seekable media as being from t=0. positionUs = !seekMap.isSeekable() ? 0 : positionUs; downstreamPositionUs = positionUs; lastSeekPositionUs = positionUs; restartFrom(positionUs); } }
@Override public void seekToUs(long positionUs) { Assertions.checkState(prepared); Assertions.checkState(enabledTrackCount > 0); // Treat all seeks into non-seekable media as being to t=0. positionUs = !seekMap.isSeekable() ? 0 : positionUs; long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs; downstreamPositionUs = positionUs; lastSeekPositionUs = positionUs; if (currentPositionUs == positionUs) { return; } // If we're not pending a reset, see if we can seek within the sample queues. boolean seekInsideBuffer = !isPendingReset(); for (int i = 0; seekInsideBuffer && i < sampleQueues.size(); i++) { seekInsideBuffer &= sampleQueues.valueAt(i).skipToKeyframeBefore(positionUs); } // If we failed to seek within the sample queues, we need to restart. if (!seekInsideBuffer) { restartFrom(positionUs); } // Either way, we need to send discontinuities to the downstream components. for (int i = 0; i < pendingDiscontinuities.length; i++) { pendingDiscontinuities[i] = true; } }