mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ParserException;
|
import com.google.android.exoplayer2.ParserException;
|
||||||
import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
||||||
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -52,16 +54,17 @@ public final class ParsingLoadable<T> implements Loadable {
|
|||||||
* Loads a single parsable object.
|
* Loads a single parsable object.
|
||||||
*
|
*
|
||||||
* @param dataSource The {@link DataSource} through which the object should be read.
|
* @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 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
|
* @return The parsed object
|
||||||
* @throws IOException Thrown if there is an error while loading or parsing.
|
* @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 {
|
throws IOException {
|
||||||
ParsingLoadable<T> loadable =
|
ParsingLoadable<T> loadable = new ParsingLoadable<>(dataSource, uri, type, parser);
|
||||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_UNKNOWN, parser);
|
|
||||||
loadable.load();
|
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 DataSource dataSource;
|
||||||
private final Parser<? extends T> parser;
|
private final Parser<? extends T> parser;
|
||||||
|
|
||||||
private volatile T result;
|
private volatile @Nullable T result;
|
||||||
private volatile long bytesLoaded;
|
private volatile long bytesLoaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,10 +111,8 @@ public final class ParsingLoadable<T> implements Loadable {
|
|||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the loaded object, or null if an object has not been loaded. */
|
||||||
* Returns the loaded object, or null if an object has not been loaded.
|
public final @Nullable T getResult() {
|
||||||
*/
|
|
||||||
public final T getResult() {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,11 +136,11 @@ public final class ParsingLoadable<T> implements Loadable {
|
|||||||
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
|
DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
|
||||||
try {
|
try {
|
||||||
inputStream.open();
|
inputStream.open();
|
||||||
result = parser.parse(dataSource.getUri(), inputStream);
|
Uri dataSourceUri = Assertions.checkNotNull(dataSource.getUri());
|
||||||
|
result = parser.parse(dataSourceUri, inputStream);
|
||||||
} finally {
|
} finally {
|
||||||
bytesLoaded = inputStream.bytesRead();
|
bytesLoaded = inputStream.bytesRead();
|
||||||
Util.closeQuietly(inputStream);
|
Util.closeQuietly(inputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public final class DashUtil {
|
|||||||
*/
|
*/
|
||||||
public static DashManifest loadManifest(DataSource dataSource, Uri uri)
|
public static DashManifest loadManifest(DataSource dataSource, Uri uri)
|
||||||
throws IOException {
|
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.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||||
import com.google.android.exoplayer2.offline.StreamKey;
|
import com.google.android.exoplayer2.offline.StreamKey;
|
||||||
@ -52,7 +53,8 @@ public final class DashDownloadHelper extends DownloadHelper {
|
|||||||
@Override
|
@Override
|
||||||
protected void prepareInternal() throws IOException {
|
protected void prepareInternal() throws IOException {
|
||||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
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. */
|
/** 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.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||||
import com.google.android.exoplayer2.offline.StreamKey;
|
import com.google.android.exoplayer2.offline.StreamKey;
|
||||||
@ -54,7 +55,7 @@ public final class HlsDownloadHelper extends DownloadHelper {
|
|||||||
@Override
|
@Override
|
||||||
protected void prepareInternal() throws IOException {
|
protected void prepareInternal() throws IOException {
|
||||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
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. */
|
/** 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 {
|
private static HlsPlaylist loadManifest(DataSource dataSource, Uri uri) throws IOException {
|
||||||
ParsingLoadable<HlsPlaylist> loadable =
|
return ParsingLoadable.load(dataSource, new HlsPlaylistParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new HlsPlaylistParser());
|
|
||||||
loadable.load();
|
|
||||||
return loadable.getResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addSegment(
|
private static void addSegment(
|
||||||
|
@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.offline;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||||
import com.google.android.exoplayer2.offline.StreamKey;
|
import com.google.android.exoplayer2.offline.StreamKey;
|
||||||
import com.google.android.exoplayer2.offline.TrackKey;
|
import com.google.android.exoplayer2.offline.TrackKey;
|
||||||
@ -49,7 +50,7 @@ public final class SsDownloadHelper extends DownloadHelper {
|
|||||||
@Override
|
@Override
|
||||||
protected void prepareInternal() throws IOException {
|
protected void prepareInternal() throws IOException {
|
||||||
DataSource dataSource = manifestDataSourceFactory.createDataSource();
|
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. */
|
/** Returns the SmoothStreaming manifest. Must not be called until after preparation completes. */
|
||||||
|
@ -69,10 +69,7 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SsManifest getManifest(DataSource dataSource, Uri uri) throws IOException {
|
protected SsManifest getManifest(DataSource dataSource, Uri uri) throws IOException {
|
||||||
ParsingLoadable<SsManifest> loadable =
|
return ParsingLoadable.load(dataSource, new SsManifestParser(), uri, C.DATA_TYPE_MANIFEST);
|
||||||
new ParsingLoadable<>(dataSource, uri, C.DATA_TYPE_MANIFEST, new SsManifestParser());
|
|
||||||
loadable.load();
|
|
||||||
return loadable.getResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user