Java Code Examples for com.google.android.exoplayer2.upstream.DataSourceException#POSITION_OUT_OF_RANGE

The following examples show how to use com.google.android.exoplayer2.upstream.DataSourceException#POSITION_OUT_OF_RANGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
static boolean isCausedByPositionOutOfRange(IOException e) {
  Throwable cause = e;
  while (cause != null) {
    if (cause instanceof DataSourceException) {
      int reason = ((DataSourceException) cause).reason;
      if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
        return true;
      }
    }
    cause = cause.getCause();
  }
  return false;
}
 
Example 2
Source File: CacheDataSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    key = cacheKeyFactory.buildCacheKey(dataSpec);
    uri = dataSpec.uri;
    actualUri = getRedirectedUriOrDefault(cache, key, /* defaultUri= */ uri);
    httpMethod = dataSpec.httpMethod;
    httpBody = dataSpec.httpBody;
    httpRequestHeaders = dataSpec.httpRequestHeaders;
    flags = dataSpec.flags;
    readPosition = dataSpec.position;

    int reason = shouldIgnoreCacheForRequest(dataSpec);
    currentRequestIgnoresCache = reason != CACHE_NOT_IGNORED;
    if (currentRequestIgnoresCache) {
      notifyCacheIgnored(reason);
    }

    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = ContentMetadata.getContentLength(cache.getContentMetadata(key));
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  } catch (Throwable e) {
    handleBeforeThrow(e);
    throw e;
  }
}
 
Example 3
Source File: CacheDataSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    key = cacheKeyFactory.buildCacheKey(dataSpec);
    uri = dataSpec.uri;
    actualUri = getRedirectedUriOrDefault(cache, key, /* defaultUri= */ uri);
    flags = dataSpec.flags;
    readPosition = dataSpec.position;

    int reason = shouldIgnoreCacheForRequest(dataSpec);
    currentRequestIgnoresCache = reason != CACHE_NOT_IGNORED;
    if (currentRequestIgnoresCache) {
      notifyCacheIgnored(reason);
    }

    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = cache.getContentLength(key);
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  } catch (IOException e) {
    handleBeforeThrow(e);
    throw e;
  }
}
 
Example 4
Source File: CacheDataSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isCausedByPositionOutOfRange(IOException e) {
  Throwable cause = e;
  while (cause != null) {
    if (cause instanceof DataSourceException) {
      int reason = ((DataSourceException) cause).reason;
      if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
        return true;
      }
    }
    cause = cause.getCause();
  }
  return false;
}
 
Example 5
Source File: CacheDataSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    key = cacheKeyFactory.buildCacheKey(dataSpec);
    uri = dataSpec.uri;
    actualUri = getRedirectedUriOrDefault(cache, key, /* defaultUri= */ uri);
    flags = dataSpec.flags;
    readPosition = dataSpec.position;

    int reason = shouldIgnoreCacheForRequest(dataSpec);
    currentRequestIgnoresCache = reason != CACHE_NOT_IGNORED;
    if (currentRequestIgnoresCache) {
      notifyCacheIgnored(reason);
    }

    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = cache.getContentLength(key);
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  } catch (IOException e) {
    handleBeforeThrow(e);
    throw e;
  }
}
 
Example 6
Source File: CacheDataSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isCausedByPositionOutOfRange(IOException e) {
  Throwable cause = e;
  while (cause != null) {
    if (cause instanceof DataSourceException) {
      int reason = ((DataSourceException) cause).reason;
      if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
        return true;
      }
    }
    cause = cause.getCause();
  }
  return false;
}
 
Example 7
Source File: FakeDataSource.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  Assertions.checkState(!opened);
  // DataSpec requires a matching close call even if open fails.
  opened = true;
  uri = dataSpec.uri;
  openedDataSpecs.add(dataSpec);
  // If the source knows that the request is unsatisfiable then fail.
  if (dataSpec.position >= totalLength || (dataSpec.length != C.LENGTH_UNSET
      && (dataSpec.position + dataSpec.length > totalLength))) {
    throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
  }
  // Scan through the segments, configuring them for the current read.
  boolean findingCurrentSegmentIndex = true;
  currentSegmentIndex = 0;
  int scannedLength = 0;
  for (Segment segment : segments) {
    segment.bytesRead =
        (int) Math.min(Math.max(0, dataSpec.position - scannedLength), segment.length);
    scannedLength += segment.length;
    findingCurrentSegmentIndex &= segment.isErrorSegment() ? segment.exceptionCleared
        : segment.bytesRead == segment.length;
    if (findingCurrentSegmentIndex) {
      currentSegmentIndex++;
    }
  }
  // Configure bytesRemaining, and return.
  if (dataSpec.length == C.LENGTH_UNSET) {
    bytesRemaining = totalLength - dataSpec.position;
    return simulateUnknownLength ? C.LENGTH_UNSET : bytesRemaining;
  } else {
    bytesRemaining = dataSpec.length;
    return bytesRemaining;
  }
}
 
Example 8
Source File: CacheUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
static boolean isCausedByPositionOutOfRange(IOException e) {
  Throwable cause = e;
  while (cause != null) {
    if (cause instanceof DataSourceException) {
      int reason = ((DataSourceException) cause).reason;
      if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
        return true;
      }
    }
    cause = cause.getCause();
  }
  return false;
}
 
Example 9
Source File: CacheDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    key = cacheKeyFactory.buildCacheKey(dataSpec);
    uri = dataSpec.uri;
    actualUri = getRedirectedUriOrDefault(cache, key, /* defaultUri= */ uri);
    httpMethod = dataSpec.httpMethod;
    flags = dataSpec.flags;
    readPosition = dataSpec.position;

    int reason = shouldIgnoreCacheForRequest(dataSpec);
    currentRequestIgnoresCache = reason != CACHE_NOT_IGNORED;
    if (currentRequestIgnoresCache) {
      notifyCacheIgnored(reason);
    }

    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = ContentMetadata.getContentLength(cache.getContentMetadata(key));
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  } catch (Throwable e) {
    handleBeforeThrow(e);
    throw e;
  }
}
 
Example 10
Source File: CacheUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
static boolean isCausedByPositionOutOfRange(IOException e) {
  Throwable cause = e;
  while (cause != null) {
    if (cause instanceof DataSourceException) {
      int reason = ((DataSourceException) cause).reason;
      if (reason == DataSourceException.POSITION_OUT_OF_RANGE) {
        return true;
      }
    }
    cause = cause.getCause();
  }
  return false;
}
 
Example 11
Source File: CacheDataSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long open(DataSpec dataSpec) throws IOException {
  try {
    key = cacheKeyFactory.buildCacheKey(dataSpec);
    uri = dataSpec.uri;
    actualUri = getRedirectedUriOrDefault(cache, key, /* defaultUri= */ uri);
    httpMethod = dataSpec.httpMethod;
    flags = dataSpec.flags;
    readPosition = dataSpec.position;

    int reason = shouldIgnoreCacheForRequest(dataSpec);
    currentRequestIgnoresCache = reason != CACHE_NOT_IGNORED;
    if (currentRequestIgnoresCache) {
      notifyCacheIgnored(reason);
    }

    if (dataSpec.length != C.LENGTH_UNSET || currentRequestIgnoresCache) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = ContentMetadata.getContentLength(cache.getContentMetadata(key));
      if (bytesRemaining != C.LENGTH_UNSET) {
        bytesRemaining -= dataSpec.position;
        if (bytesRemaining <= 0) {
          throw new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE);
        }
      }
    }
    openNextSource(false);
    return bytesRemaining;
  } catch (Throwable e) {
    handleBeforeThrow(e);
    throw e;
  }
}