Correctly report type of ParsingLoadable.
The helper method only reported DATA_TYPE_UNKNOWN even if the actual type is known. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=200067296
This commit is contained in:
parent
c1181000f9
commit
877c6965c3
@ -16,9 +16,11 @@
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -52,16 +54,17 @@ public final class ParsingLoadable<T> implements Loadable {
|
||||
* Loads a single parsable object.
|
||||
*
|
||||
* @param dataSource The {@link DataSource} through which the object should be read.
|
||||
* @param parser The {@link Parser} to parse the object from the response.
|
||||
* @param uri The {@link Uri} of the object to read.
|
||||
* @param type The type of the data. One of the {@link C}{@code DATA_TYPE_*} constants.
|
||||
* @return The parsed object
|
||||
* @throws IOException Thrown if there is an error while loading or parsing.
|
||||
*/
|
||||
public static <T> T load(DataSource dataSource, Parser<? extends T> parser, Uri uri)
|
||||
public static <T> T load(DataSource dataSource, Parser<? extends T> parser, Uri uri, int type)
|
||||
throws IOException {
|
||||
ParsingLoadable<T> loadable =
|
||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_UNKNOWN, parser);
|
||||
ParsingLoadable<T> loadable = new ParsingLoadable<>(dataSource, uri, type, parser);
|
||||
loadable.load();
|
||||
return loadable.getResult();
|
||||
return Assertions.checkNotNull(loadable.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +80,7 @@ public final class ParsingLoadable<T> implements Loadable {
|
||||
private final DataSource dataSource;
|
||||
private final Parser<? extends T> parser;
|
||||
|
||||
private volatile T result;
|
||||
private volatile @Nullable T result;
|
||||
private volatile long bytesLoaded;
|
||||
|
||||
/**
|
||||
@ -108,10 +111,8 @@ public final class ParsingLoadable<T> implements Loadable {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loaded object, or null if an object has not been loaded.
|
||||
*/
|
||||
public final T getResult() {
|
||||
/** Returns the loaded object, or null if an object has not been loaded. */
|
||||
public final @Nullable T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -135,11 +136,11 @@ public final class ParsingLoadable<T> implements Loadable {
|
||||
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
|
||||
try {
|
||||
inputStream.open();
|
||||
result = parser.parse(dataSource.getUri(), inputStream);
|
||||
Uri dataSourceUri = Assertions.checkNotNull(dataSource.getUri());
|
||||
result = parser.parse(dataSourceUri, inputStream);
|
||||
} finally {
|
||||
bytesLoaded = inputStream.bytesRead();
|
||||
Util.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public final class DashUtil {
|
||||
*/
|
||||
public static DashManifest loadManifest(DataSource dataSource, Uri uri)
|
||||
throws IOException {
|
||||
return ParsingLoadable.load(dataSource, new DashManifestParser(), uri);
|
||||
return ParsingLoadable.load(dataSource, new DashManifestParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.dash.offline;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
@ -52,7 +53,8 @@ public final class DashDownloadHelper extends DownloadHelper {
|
||||
@Override
|
||||
protected void prepareInternal() throws IOException {
|
||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
||||
manifest = ParsingLoadable.load(dataSource, new DashManifestParser(), uri);
|
||||
manifest =
|
||||
ParsingLoadable.load(dataSource, new DashManifestParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
/** Returns the DASH manifest. Must not be called until after preparation completes. */
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.hls.offline;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
@ -54,7 +55,7 @@ public final class HlsDownloadHelper extends DownloadHelper {
|
||||
@Override
|
||||
protected void prepareInternal() throws IOException {
|
||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
||||
playlist = ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri);
|
||||
playlist = ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
/** Returns the HLS playlist. Must not be called until after preparation completes. */
|
||||
|
@ -118,10 +118,7 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
|
||||
}
|
||||
|
||||
private static HlsPlaylist loadManifest(DataSource dataSource, Uri uri) throws IOException {
|
||||
ParsingLoadable<HlsPlaylist> loadable =
|
||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new HlsPlaylistParser());
|
||||
loadable.load();
|
||||
return loadable.getResult();
|
||||
return ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
private static void addSegment(
|
||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.offline;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.offline.TrackKey;
|
||||
@ -49,7 +50,7 @@ public final class SsDownloadHelper extends DownloadHelper {
|
||||
@Override
|
||||
protected void prepareInternal() throws IOException {
|
||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
||||
manifest = ParsingLoadable.load(dataSource, new SsManifestParser(), uri);
|
||||
manifest = ParsingLoadable.load(dataSource, new SsManifestParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
/** Returns the SmoothStreaming manifest. Must not be called until after preparation completes. */
|
||||
|
@ -69,10 +69,7 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
|
||||
|
||||
@Override
|
||||
protected SsManifest getManifest(DataSource dataSource, Uri uri) throws IOException {
|
||||
ParsingLoadable<SsManifest> loadable =
|
||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new SsManifestParser());
|
||||
loadable.load();
|
||||
return loadable.getResult();
|
||||
return ParsingLoadable.load(dataSource, new SsManifestParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user