本文整理汇总了Java中com.google.android.exoplayer2.util.Util.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java Util.closeQuietly方法的具体用法?Java Util.closeQuietly怎么用?Java Util.closeQuietly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.exoplayer2.util.Util
的用法示例。
在下文中一共展示了Util.closeQuietly方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@Override
protected List<SampleGroup> doInBackground(String... uris) {
List<SampleGroup> result = new ArrayList<>();
Context context = getApplicationContext();
String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
for (String uri : uris) {
DataSpec dataSpec = new DataSpec(Uri.parse(uri));
InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
try {
readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
} catch (Exception e) {
Log.e(TAG, "Error loading sample list: " + uri, e);
sawError = true;
} finally {
Util.closeQuietly(dataSource);
}
}
return result;
}
示例2: executePost
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
throws IOException {
HttpDataSource dataSource = dataSourceFactory.createDataSource();
if (requestProperties != null) {
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
}
}
DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
DataSpec.FLAG_ALLOW_GZIP);
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
try {
return Util.toByteArray(inputStream);
} finally {
Util.closeQuietly(inputStream);
}
}
示例3: maybeLoadInitData
import com.google.android.exoplayer2.util.Util; //导入方法依赖的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;
}
示例4: executePost
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
byte[] data, Map<String, String> requestProperties) throws IOException {
HttpDataSource dataSource = dataSourceFactory.createDataSource();
if (requestProperties != null) {
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
}
}
DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
DataSpec.FLAG_ALLOW_GZIP);
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
try {
return Util.toByteArray(inputStream);
} finally {
Util.closeQuietly(inputStream);
}
}
示例5: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的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);
}
}
示例6: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@Override
public final void load() throws IOException, InterruptedException {
try {
dataSource.open(dataSpec);
limit = 0;
int bytesRead = 0;
while (bytesRead != C.RESULT_END_OF_INPUT && !loadCanceled) {
maybeExpandData();
bytesRead = dataSource.read(data, limit, READ_GRANULARITY);
if (bytesRead != -1) {
limit += bytesRead;
}
}
if (!loadCanceled) {
consume(data, limit);
}
} finally {
Util.closeQuietly(dataSource);
}
}
示例7: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@Override
public void load() throws IOException, InterruptedException {
// We always load from the beginning, so reset the sampleSize to 0.
sampleSize = 0;
try {
// Create and open the input.
dataSource.open(new DataSpec(uri));
// Load the sample data.
int result = 0;
while (result != C.RESULT_END_OF_INPUT) {
sampleSize += result;
if (sampleData == null) {
sampleData = new byte[INITIAL_SAMPLE_SIZE];
} else if (sampleSize == sampleData.length) {
sampleData = Arrays.copyOf(sampleData, sampleData.length * 2);
}
result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize);
}
} finally {
Util.closeQuietly(dataSource);
}
}
示例8: closeCurrentOutputStream
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@SuppressWarnings("ThrowFromFinallyBlock")
private void closeCurrentOutputStream() throws IOException {
if (outputStream == null) {
return;
}
boolean success = false;
try {
outputStream.flush();
underlyingFileOutputStream.getFD().sync();
success = true;
} finally {
Util.closeQuietly(outputStream);
outputStream = null;
File fileToCommit = file;
file = null;
if (success) {
cache.commitFile(fileToCommit);
} else {
fileToCommit.delete();
}
}
}
示例9: parse
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@Override
public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
Queue<String> extraLines = new LinkedList<>();
String line;
try {
if (!checkPlaylistHeader(reader)) {
throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.",
uri);
}
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
// Do nothing.
} else if (line.startsWith(TAG_STREAM_INF)) {
extraLines.add(line);
return parseMasterPlaylist(new LineIterator(extraLines, reader), uri.toString());
} else if (line.startsWith(TAG_TARGET_DURATION)
|| line.startsWith(TAG_MEDIA_SEQUENCE)
|| line.startsWith(TAG_MEDIA_DURATION)
|| line.startsWith(TAG_KEY)
|| line.startsWith(TAG_BYTERANGE)
|| line.equals(TAG_DISCONTINUITY)
|| line.equals(TAG_DISCONTINUITY_SEQUENCE)
|| line.equals(TAG_ENDLIST)) {
extraLines.add(line);
return parseMediaPlaylist(new LineIterator(extraLines, reader), uri.toString());
} else {
extraLines.add(line);
}
}
} finally {
Util.closeQuietly(reader);
}
throw new ParserException("Failed to parse the playlist, could not identify any tags.");
}
示例10: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
long length = dataSource.open(loadDataSpec);
if (length != C.LENGTH_UNSET) {
length += bytesLoaded;
}
ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, bytesLoaded, length);
BaseMediaChunkOutput output = getOutput();
output.setSampleOffsetUs(0);
TrackOutput trackOutput = output.track(0, trackType);
trackOutput.format(sampleFormat);
// Load the sample data.
int result = 0;
while (result != C.RESULT_END_OF_INPUT) {
bytesLoaded += result;
result = trackOutput.sampleData(extractorInput, Integer.MAX_VALUE, true);
}
int sampleSize = bytesLoaded;
trackOutput.sampleMetadata(startTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
} finally {
Util.closeQuietly(dataSource);
}
loadCompleted = true;
}
示例11: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的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: load
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
@Override
public final void load() throws IOException, InterruptedException {
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
try {
inputStream.open();
result = parser.parse(dataSource.getUri(), inputStream);
} finally {
bytesLoaded = inputStream.bytesRead();
Util.closeQuietly(inputStream);
}
}
示例13: readAndDiscard
import com.google.android.exoplayer2.util.Util; //导入方法依赖的package包/类
/**
* Reads and discards all data specified by the {@code dataSpec}.
*
* @param dataSpec Defines the data to be read.
* @param dataSource The {@link DataSource} to read the data from.
* @param buffer The buffer to be used while downloading.
* @param priorityTaskManager If not null it's used to check whether it is allowed to proceed with
* caching.
* @param priority The priority of this task.
* @return Number of read bytes, or 0 if no data is available because the end of the opened range
* has been reached.
*/
private static long readAndDiscard(DataSpec dataSpec, DataSource dataSource, byte[] buffer,
PriorityTaskManager priorityTaskManager, int priority)
throws IOException, InterruptedException {
while (true) {
if (priorityTaskManager != null) {
// Wait for any other thread with higher priority to finish its job.
priorityTaskManager.proceed(priority);
}
try {
dataSource.open(dataSpec);
long totalRead = 0;
while (true) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
int read = dataSource.read(buffer, 0, buffer.length);
if (read == C.RESULT_END_OF_INPUT) {
return totalRead;
}
totalRead += read;
}
} catch (PriorityTaskManager.PriorityTooLowException exception) {
// catch and try again
} finally {
Util.closeQuietly(dataSource);
}
}
}
示例14: loadMedia
import com.google.android.exoplayer2.util.Util; //导入方法依赖的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;
}