com.google.android.exoplayer2.offline.DownloadRequest.UnsupportedRequestException Java Examples
The following examples show how to use
com.google.android.exoplayer2.offline.DownloadRequest.UnsupportedRequestException.
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: ActionFile.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Loads {@link DownloadRequest DownloadRequests} from the file. * * @return The loaded {@link DownloadRequest DownloadRequests}, or an empty array if the file does * not exist. * @throws IOException If there is an error reading the file. */ public DownloadRequest[] load() throws IOException { if (!exists()) { return new DownloadRequest[0]; } @Nullable InputStream inputStream = null; try { inputStream = atomicFile.openRead(); DataInputStream dataInputStream = new DataInputStream(inputStream); int version = dataInputStream.readInt(); if (version > VERSION) { throw new IOException("Unsupported action file version: " + version); } int actionCount = dataInputStream.readInt(); ArrayList<DownloadRequest> actions = new ArrayList<>(); for (int i = 0; i < actionCount; i++) { try { actions.add(readDownloadRequest(dataInputStream)); } catch (UnsupportedRequestException e) { // remove DownloadRequest is not supported. Ignore and continue loading rest. } } return actions.toArray(new DownloadRequest[0]); } finally { Util.closeQuietly(inputStream); } }
Example #2
Source File: ActionFile.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Loads {@link DownloadRequest DownloadRequests} from the file. * * @return The loaded {@link DownloadRequest DownloadRequests}, or an empty array if the file does * not exist. * @throws IOException If there is an error reading the file. */ public DownloadRequest[] load() throws IOException { if (!exists()) { return new DownloadRequest[0]; } InputStream inputStream = null; try { inputStream = atomicFile.openRead(); DataInputStream dataInputStream = new DataInputStream(inputStream); int version = dataInputStream.readInt(); if (version > VERSION) { throw new IOException("Unsupported action file version: " + version); } int actionCount = dataInputStream.readInt(); ArrayList<DownloadRequest> actions = new ArrayList<>(); for (int i = 0; i < actionCount; i++) { try { actions.add(readDownloadRequest(dataInputStream)); } catch (UnsupportedRequestException e) { // remove DownloadRequest is not supported. Ignore and continue loading rest. } } return actions.toArray(new DownloadRequest[0]); } finally { Util.closeQuietly(inputStream); } }
Example #3
Source File: ActionFile.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Loads {@link DownloadRequest DownloadRequests} from the file. * * @return The loaded {@link DownloadRequest DownloadRequests}, or an empty array if the file does * not exist. * @throws IOException If there is an error reading the file. */ public DownloadRequest[] load() throws IOException { if (!exists()) { return new DownloadRequest[0]; } InputStream inputStream = null; try { inputStream = atomicFile.openRead(); DataInputStream dataInputStream = new DataInputStream(inputStream); int version = dataInputStream.readInt(); if (version > VERSION) { throw new IOException("Unsupported action file version: " + version); } int actionCount = dataInputStream.readInt(); ArrayList<DownloadRequest> actions = new ArrayList<>(); for (int i = 0; i < actionCount; i++) { try { actions.add(readDownloadRequest(dataInputStream)); } catch (UnsupportedRequestException e) { // remove DownloadRequest is not supported. Ignore and continue loading rest. } } return actions.toArray(new DownloadRequest[0]); } finally { Util.closeQuietly(inputStream); } }
Example #4
Source File: ActionFile.java From MediaSDK with Apache License 2.0 | 4 votes |
private static DownloadRequest readDownloadRequest(DataInputStream input) throws IOException { String type = input.readUTF(); int version = input.readInt(); Uri uri = Uri.parse(input.readUTF()); boolean isRemoveAction = input.readBoolean(); int dataLength = input.readInt(); @Nullable byte[] data; if (dataLength != 0) { data = new byte[dataLength]; input.readFully(data); } else { data = null; } // Serialized version 0 progressive actions did not contain keys. boolean isLegacyProgressive = version == 0 && DownloadRequest.TYPE_PROGRESSIVE.equals(type); List<StreamKey> keys = new ArrayList<>(); if (!isLegacyProgressive) { int keyCount = input.readInt(); for (int i = 0; i < keyCount; i++) { keys.add(readKey(type, version, input)); } } // Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key. boolean isLegacySegmented = version < 2 && (DownloadRequest.TYPE_DASH.equals(type) || DownloadRequest.TYPE_HLS.equals(type) || DownloadRequest.TYPE_SS.equals(type)); @Nullable String customCacheKey = null; if (!isLegacySegmented) { customCacheKey = input.readBoolean() ? input.readUTF() : null; } // Serialized version 0, 1 and 2 did not contain an id. We need to generate one. String id = version < 3 ? generateDownloadId(uri, customCacheKey) : input.readUTF(); if (isRemoveAction) { // Remove actions are not supported anymore. throw new UnsupportedRequestException(); } return new DownloadRequest(id, type, uri, keys, customCacheKey, data); }
Example #5
Source File: ActionFile.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private static DownloadRequest readDownloadRequest(DataInputStream input) throws IOException { String type = input.readUTF(); int version = input.readInt(); Uri uri = Uri.parse(input.readUTF()); boolean isRemoveAction = input.readBoolean(); int dataLength = input.readInt(); byte[] data; if (dataLength != 0) { data = new byte[dataLength]; input.readFully(data); } else { data = null; } // Serialized version 0 progressive actions did not contain keys. boolean isLegacyProgressive = version == 0 && DownloadRequest.TYPE_PROGRESSIVE.equals(type); List<StreamKey> keys = new ArrayList<>(); if (!isLegacyProgressive) { int keyCount = input.readInt(); for (int i = 0; i < keyCount; i++) { keys.add(readKey(type, version, input)); } } // Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key. boolean isLegacySegmented = version < 2 && (DownloadRequest.TYPE_DASH.equals(type) || DownloadRequest.TYPE_HLS.equals(type) || DownloadRequest.TYPE_SS.equals(type)); String customCacheKey = null; if (!isLegacySegmented) { customCacheKey = input.readBoolean() ? input.readUTF() : null; } // Serialized version 0, 1 and 2 did not contain an id. We need to generate one. String id = version < 3 ? generateDownloadId(uri, customCacheKey) : input.readUTF(); if (isRemoveAction) { // Remove actions are not supported anymore. throw new UnsupportedRequestException(); } return new DownloadRequest(id, type, uri, keys, customCacheKey, data); }
Example #6
Source File: ActionFile.java From Telegram with GNU General Public License v2.0 | 4 votes |
private static DownloadRequest readDownloadRequest(DataInputStream input) throws IOException { String type = input.readUTF(); int version = input.readInt(); Uri uri = Uri.parse(input.readUTF()); boolean isRemoveAction = input.readBoolean(); int dataLength = input.readInt(); byte[] data; if (dataLength != 0) { data = new byte[dataLength]; input.readFully(data); } else { data = null; } // Serialized version 0 progressive actions did not contain keys. boolean isLegacyProgressive = version == 0 && DownloadRequest.TYPE_PROGRESSIVE.equals(type); List<StreamKey> keys = new ArrayList<>(); if (!isLegacyProgressive) { int keyCount = input.readInt(); for (int i = 0; i < keyCount; i++) { keys.add(readKey(type, version, input)); } } // Serialized version 0 and 1 DASH/HLS/SS actions did not contain a custom cache key. boolean isLegacySegmented = version < 2 && (DownloadRequest.TYPE_DASH.equals(type) || DownloadRequest.TYPE_HLS.equals(type) || DownloadRequest.TYPE_SS.equals(type)); String customCacheKey = null; if (!isLegacySegmented) { customCacheKey = input.readBoolean() ? input.readUTF() : null; } // Serialized version 0, 1 and 2 did not contain an id. We need to generate one. String id = version < 3 ? generateDownloadId(uri, customCacheKey) : input.readUTF(); if (isRemoveAction) { // Remove actions are not supported anymore. throw new UnsupportedRequestException(); } return new DownloadRequest(id, type, uri, keys, customCacheKey, data); }