本文整理汇总了Java中com.google.android.exoplayer2.extractor.ExtractorInput.getPosition方法的典型用法代码示例。如果您正苦于以下问题:Java ExtractorInput.getPosition方法的具体用法?Java ExtractorInput.getPosition怎么用?Java ExtractorInput.getPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.exoplayer2.extractor.ExtractorInput
的用法示例。
在下文中一共展示了ExtractorInput.getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeLoadInitData
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void maybeLoadInitData() throws IOException, InterruptedException {
if (previousExtractor == extractor || initLoadCompleted || initDataSpec == null) {
// According to spec, for packed audio, initDataSpec is expected to be null.
return;
}
DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded);
try {
ExtractorInput input = new DefaultExtractorInput(initDataSource,
initSegmentDataSpec.absoluteStreamPosition, initDataSource.open(initSegmentDataSpec));
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractor.read(input, null);
}
} finally {
initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition);
}
} finally {
Util.closeQuietly(dataSource);
}
initLoadCompleted = true;
}
示例2: readAtomPayload
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Processes the atom payload. If {@link #atomData} is null and the size is at or above the
* threshold {@link #RELOAD_MINIMUM_SEEK_DISTANCE}, {@code true} is returned and the caller should
* restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
*/
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
throws IOException, InterruptedException {
long atomPayloadSize = atomSize - atomHeaderBytesRead;
long atomEndPosition = input.getPosition() + atomPayloadSize;
boolean seekRequired = false;
if (atomData != null) {
input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize);
if (atomType == Atom.TYPE_ftyp) {
isQuickTime = processFtypAtom(atomData);
} else if (!containerAtoms.isEmpty()) {
containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
}
} else {
// We don't need the data. Skip or seek, depending on how large the atom is.
if (atomPayloadSize < RELOAD_MINIMUM_SEEK_DISTANCE) {
input.skipFully((int) atomPayloadSize);
} else {
positionHolder.position = input.getPosition() + atomPayloadSize;
seekRequired = true;
}
}
processAtomEnded(atomEndPosition);
return seekRequired && parserState != STATE_READING_SAMPLE;
}
示例3: readEncryptionData
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void readEncryptionData(ExtractorInput input) throws IOException, InterruptedException {
TrackBundle nextTrackBundle = null;
long nextDataOffset = Long.MAX_VALUE;
int trackBundlesSize = trackBundles.size();
for (int i = 0; i < trackBundlesSize; i++) {
TrackFragment trackFragment = trackBundles.valueAt(i).fragment;
if (trackFragment.sampleEncryptionDataNeedsFill
&& trackFragment.auxiliaryDataPosition < nextDataOffset) {
nextDataOffset = trackFragment.auxiliaryDataPosition;
nextTrackBundle = trackBundles.valueAt(i);
}
}
if (nextTrackBundle == null) {
parserState = STATE_READING_SAMPLE_START;
return;
}
int bytesToSkip = (int) (nextDataOffset - input.getPosition());
if (bytesToSkip < 0) {
throw new ParserException("Offset to encryption data was negative.");
}
input.skipFully(bytesToSkip);
nextTrackBundle.fragment.fillEncryptionData(input);
}
示例4: load
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (bytesLoaded == 0) {
extractorWrapper.init(null);
}
// Load and decode the initialization data.
try {
Extractor extractor = extractorWrapper.extractor;
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractor.read(input, null);
}
Assertions.checkState(result != Extractor.RESULT_SEEK);
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
Util.closeQuietly(dataSource);
}
}
示例5: load
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (bytesLoaded == 0) {
// Set the target to ourselves.
extractorWrapper.init(this, this);
}
// Load and decode the initialization data.
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractorWrapper.read(input);
}
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
dataSource.close();
}
}
示例6: load
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@Override
public void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractor.read(input, null);
}
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
dataSource.close();
}
}
示例7: readHeaders
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
boolean readingHeaders = true;
while (readingHeaders) {
if (!oggPacket.populate(input)) {
state = STATE_END_OF_INPUT;
return Extractor.RESULT_END_OF_INPUT;
}
lengthOfReadPacket = input.getPosition() - payloadStartPosition;
readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
if (readingHeaders) {
payloadStartPosition = input.getPosition();
}
}
sampleRate = setupData.format.sampleRate;
if (!formatSet) {
trackOutput.format(setupData.format);
formatSet = true;
}
if (setupData.oggSeeker != null) {
oggSeeker = setupData.oggSeeker;
} else if (input.getLength() == C.LENGTH_UNSET) {
oggSeeker = new UnseekableOggSeeker();
} else {
OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
firstPayloadPageHeader.granulePosition);
}
setupData = null;
state = STATE_READ_PAYLOAD;
// First payload packet. Trim the payload array of the ogg packet after headers have been read.
oggPacket.trimPayload();
return Extractor.RESULT_CONTINUE;
}
示例8: read
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@Override
public long read(ExtractorInput input) throws IOException, InterruptedException {
switch (state) {
case STATE_IDLE:
return -1;
case STATE_SEEK_TO_END:
positionBeforeSeekToEnd = input.getPosition();
state = STATE_READ_LAST_PAGE;
// Seek to the end just before the last page of stream to get the duration.
long lastPageSearchPosition = endPosition - OggPageHeader.MAX_PAGE_SIZE;
if (lastPageSearchPosition > positionBeforeSeekToEnd) {
return lastPageSearchPosition;
}
// Fall through.
case STATE_READ_LAST_PAGE:
totalGranules = readGranuleOfLastPage(input);
state = STATE_IDLE;
return positionBeforeSeekToEnd;
case STATE_SEEK:
long currentGranule;
if (targetGranule == 0) {
currentGranule = 0;
} else {
long position = getNextSeekPosition(targetGranule, input);
if (position >= 0) {
return position;
}
currentGranule = skipToPageOfGranule(input, targetGranule, -(position + 2));
}
state = STATE_IDLE;
return -(currentGranule + 2);
default:
// Never happens.
throw new IllegalStateException();
}
}
示例9: skipToNextPage
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Skips to the next page. Searches for the next page header.
*
* @param input The {@code ExtractorInput} to skip to the next page.
* @param until Searches until this position.
* @return true if the next page is found.
* @throws IOException thrown if peeking/reading from the input fails.
* @throws InterruptedException thrown if interrupted while peeking/reading from the input.
*/
//@VisibleForTesting
boolean skipToNextPage(ExtractorInput input, long until)
throws IOException, InterruptedException {
until = Math.min(until + 3, endPosition);
byte[] buffer = new byte[2048];
int peekLength = buffer.length;
while (true) {
if (input.getPosition() + peekLength > until) {
// Make sure to not peek beyond the end of the input.
peekLength = (int) (until - input.getPosition());
if (peekLength < 4) {
// Not found until end.
return false;
}
}
input.peekFully(buffer, 0, peekLength, false);
for (int i = 0; i < peekLength - 3; i++) {
if (buffer[i] == 'O' && buffer[i + 1] == 'g' && buffer[i + 2] == 'g'
&& buffer[i + 3] == 'S') {
// Match! Skip to the start of the pattern.
input.skipFully(i);
return true;
}
}
// Overlap by not skipping the entire peekLength.
input.skipFully(peekLength - 3);
}
}
示例10: readGranuleOfLastPage
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Skips to the last Ogg page in the stream and reads the header's granule field which is the
* total number of samples per channel.
*
* @param input The {@link ExtractorInput} to read from.
* @return the total number of samples of this input.
* @throws IOException thrown if reading from the input fails.
* @throws InterruptedException thrown if interrupted while reading from the input.
*/
//@VisibleForTesting
long readGranuleOfLastPage(ExtractorInput input)
throws IOException, InterruptedException {
skipToNextPage(input);
pageHeader.reset();
while ((pageHeader.type & 0x04) != 0x04 && input.getPosition() < endPosition) {
pageHeader.populate(input, false);
input.skipFully(pageHeader.headerSize + pageHeader.bodySize);
}
return pageHeader.granulePosition;
}
示例11: load
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (bytesLoaded == 0) {
// Configure the output and set it as the target for the extractor wrapper.
BaseMediaChunkOutput output = getOutput();
output.setSampleOffsetUs(sampleOffsetUs);
extractorWrapper.init(output);
}
// Load and decode the sample data.
try {
Extractor extractor = extractorWrapper.extractor;
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractor.read(input, null);
}
Assertions.checkState(result != Extractor.RESULT_SEEK);
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
Util.closeQuietly(dataSource);
}
loadCompleted = true;
}
示例12: readHeaders
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
boolean readingHeaders = true;
while (readingHeaders) {
if (!oggPacket.populate(input)) {
state = STATE_END_OF_INPUT;
return Extractor.RESULT_END_OF_INPUT;
}
lengthOfReadPacket = input.getPosition() - payloadStartPosition;
readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
if (readingHeaders) {
payloadStartPosition = input.getPosition();
}
}
sampleRate = setupData.format.sampleRate;
if (!formatSet) {
trackOutput.format(setupData.format);
formatSet = true;
}
if (setupData.oggSeeker != null) {
oggSeeker = setupData.oggSeeker;
} else if (input.getLength() == C.LENGTH_UNSET) {
oggSeeker = new UnseekableOggSeeker();
} else {
OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
firstPayloadPageHeader.granulePosition);
}
setupData = null;
state = STATE_READ_PAYLOAD;
return Extractor.RESULT_CONTINUE;
}
示例13: load
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (bytesLoaded == 0) {
// Set the target to ourselves.
DefaultTrackOutput trackOutput = getTrackOutput();
trackOutput.formatWithOffset(sampleFormat, sampleOffsetUs);
extractorWrapper.init(this, trackOutput);
}
// Load and decode the sample data.
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractorWrapper.read(input);
}
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
dataSource.close();
}
loadCompleted = true;
}
示例14: read
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
throws IOException, InterruptedException {
while (true) {
switch (parserState) {
case STATE_AFTER_SEEK:
if (input.getPosition() == 0) {
enterReadingAtomHeaderState();
} else {
parserState = STATE_READING_SAMPLE;
}
break;
case STATE_READING_ATOM_HEADER:
if (!readAtomHeader(input)) {
return RESULT_END_OF_INPUT;
}
break;
case STATE_READING_ATOM_PAYLOAD:
if (readAtomPayload(input, seekPosition)) {
return RESULT_SEEK;
}
break;
default:
return readSample(input, seekPosition);
}
}
}
示例15: loadMedia
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void loadMedia() throws IOException, InterruptedException {
// If we previously fed part of this chunk to the extractor, we need to skip it this time. For
// encrypted content we need to skip the data by reading it through the source, so as to ensure
// correct decryption of the remainder of the chunk. For clear content, we can request the
// remainder of the chunk directly.
DataSpec loadDataSpec;
boolean skipLoadedBytes;
if (isEncrypted) {
loadDataSpec = dataSpec;
skipLoadedBytes = bytesLoaded != 0;
} else {
loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
skipLoadedBytes = false;
}
if (!isMasterTimestampSource) {
timestampAdjuster.waitUntilInitialized();
} else if (timestampAdjuster.getFirstSampleTimestampUs() == TimestampAdjuster.DO_NOT_OFFSET) {
// We're the master and we haven't set the desired first sample timestamp yet.
timestampAdjuster.setFirstSampleTimestampUs(startTimeUs);
}
try {
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (extractor == null) {
// Media segment format is packed audio.
long id3Timestamp = peekId3PrivTimestamp(input);
extractor = buildPackedAudioExtractor(id3Timestamp != C.TIME_UNSET
? timestampAdjuster.adjustTsTimestamp(id3Timestamp) : startTimeUs);
}
if (skipLoadedBytes) {
input.skipFully(bytesLoaded);
}
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractor.read(input, null);
}
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
Util.closeQuietly(dataSource);
}
loadCompleted = true;
}