/** * @param manifestUri The manifest location. * @param uriDataSource The {@link UriDataSource} to use when loading the manifest. * @param parser A parser to parse the loaded manifest data. * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be * null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. */ public ManifestFetcher(String manifestUri, UriDataSource uriDataSource, UriLoadable.Parser<T> parser, Handler eventHandler, EventListener eventListener) { this.parser = parser; this.manifestUri = manifestUri; this.uriDataSource = uriDataSource; this.eventHandler = eventHandler; this.eventListener = eventListener; }
public SingleFetchHelper(UriLoadable<T> singleUseLoadable, Looper callbackLooper, ManifestCallback<T> wrappedCallback) { this.singleUseLoadable = singleUseLoadable; this.callbackLooper = callbackLooper; this.wrappedCallback = wrappedCallback; singleUseLoader = new Loader("manifestLoader:single"); }
/** * Loads a manifest. * * @param context A context. * @param tag A tag to use for logging. * @param url The manifest url. * @param parser A suitable parser for the manifest. * @return The parser manifest. * @throws IOException If an error occurs loading the manifest. */ public static <T> T loadManifest(Context context, String tag, String url, UriLoadable.Parser<T> parser) throws IOException { String userAgent = getUserAgent(context); int retryCount = 0; while (true) { try { DefaultUriDataSource manifestDataSource = new DefaultUriDataSource(context, userAgent); ManifestFetcher<T> manifestFetcher = new ManifestFetcher<>(url, manifestDataSource, parser); SyncManifestCallback<T> callback = new SyncManifestCallback<>(); manifestFetcher.singleLoad(context.getMainLooper(), callback); return callback.getResult(); } catch (IOException e) { if (retryCount++ < MANIFEST_LOAD_MAX_RETRY_COUNT) { // Sleep, then try again. Log.e(tag, "Failed to load manifest", e); try { Thread.sleep(5000); } catch (InterruptedException e2) { // Never happens. throw new InterruptedIOException(); } } else { // Give up. throw e; } } } }
private void resolveHttp(UriLoadable.Parser<Long> parser) { singleUseLoader = new Loader("utctiming"); singleUseLoadable = new UriLoadable<>(timingElement.value, uriDataSource, parser); singleUseLoader.startLoading(singleUseLoadable, this); }
/** * @param manifestUri The manifest location. * @param uriDataSource The {@link UriDataSource} to use when loading the manifest. * @param parser A parser to parse the loaded manifest data. */ public ManifestFetcher(String manifestUri, UriDataSource uriDataSource, UriLoadable.Parser<T> parser) { this(manifestUri, uriDataSource, parser, null, null); }
/** * Performs a single manifest load. * * @param callbackLooper The looper associated with the thread on which the callback should be * invoked. * @param callback The callback to receive the result. */ public void singleLoad(Looper callbackLooper, final ManifestCallback<T> callback) { SingleFetchHelper fetchHelper = new SingleFetchHelper( new UriLoadable<>(manifestUri, uriDataSource, parser), callbackLooper, callback); fetchHelper.startLoading(); }