Remove deprecated parts of demo app IntentUtil

PiperOrigin-RevId: 324604419
This commit is contained in:
olly 2020-08-03 16:03:15 +01:00 committed by kim-vde
parent 33fe3a47e3
commit be88143fcd
7 changed files with 46 additions and 50 deletions

View File

@ -24,7 +24,6 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -63,8 +62,6 @@ public class IntentUtil {
public static final String MIME_TYPE_EXTRA = "mime_type"; public static final String MIME_TYPE_EXTRA = "mime_type";
public static final String CLIP_START_POSITION_MS_EXTRA = "clip_start_position_ms"; public static final String CLIP_START_POSITION_MS_EXTRA = "clip_start_position_ms";
public static final String CLIP_END_POSITION_MS_EXTRA = "clip_end_position_ms"; public static final String CLIP_END_POSITION_MS_EXTRA = "clip_end_position_ms";
// For backwards compatibility only.
public static final String EXTENSION_EXTRA = "extension";
public static final String DRM_SCHEME_EXTRA = "drm_scheme"; public static final String DRM_SCHEME_EXTRA = "drm_scheme";
public static final String DRM_LICENSE_URL_EXTRA = "drm_license_url"; public static final String DRM_LICENSE_URL_EXTRA = "drm_license_url";
@ -72,12 +69,11 @@ public class IntentUtil {
public static final String DRM_SESSION_FOR_CLEAR_TYPES_EXTRA = "drm_session_for_clear_types"; public static final String DRM_SESSION_FOR_CLEAR_TYPES_EXTRA = "drm_session_for_clear_types";
public static final String DRM_MULTI_SESSION_EXTRA = "drm_multi_session"; public static final String DRM_MULTI_SESSION_EXTRA = "drm_multi_session";
public static final String DRM_FORCE_DEFAULT_LICENSE_URI_EXTRA = "drm_force_default_license_uri"; public static final String DRM_FORCE_DEFAULT_LICENSE_URI_EXTRA = "drm_force_default_license_uri";
public static final String AD_TAG_URI_EXTRA = "ad_tag_uri"; public static final String AD_TAG_URI_EXTRA = "ad_tag_uri";
public static final String SUBTITLE_URI_EXTRA = "subtitle_uri"; public static final String SUBTITLE_URI_EXTRA = "subtitle_uri";
public static final String SUBTITLE_MIME_TYPE_EXTRA = "subtitle_mime_type"; public static final String SUBTITLE_MIME_TYPE_EXTRA = "subtitle_mime_type";
public static final String SUBTITLE_LANGUAGE_EXTRA = "subtitle_language"; public static final String SUBTITLE_LANGUAGE_EXTRA = "subtitle_language";
// For backwards compatibility only.
public static final String DRM_SCHEME_UUID_EXTRA = "drm_scheme_uuid";
public static final String PREFER_EXTENSION_DECODERS_EXTRA = "prefer_extension_decoders"; public static final String PREFER_EXTENSION_DECODERS_EXTRA = "prefer_extension_decoders";
@ -122,31 +118,9 @@ public class IntentUtil {
} }
} }
/** Makes a best guess to infer the MIME type from a {@link Uri} and an optional extension. */
@Nullable
public static String inferAdaptiveStreamMimeType(Uri uri, @Nullable String extension) {
@C.ContentType int contentType = Util.inferContentType(uri, extension);
switch (contentType) {
case C.TYPE_DASH:
return MimeTypes.APPLICATION_MPD;
case C.TYPE_HLS:
return MimeTypes.APPLICATION_M3U8;
case C.TYPE_SS:
return MimeTypes.APPLICATION_SS;
case C.TYPE_OTHER:
default:
return null;
}
}
private static MediaItem createMediaItemFromIntent( private static MediaItem createMediaItemFromIntent(
Uri uri, Intent intent, String extrasKeySuffix) { Uri uri, Intent intent, String extrasKeySuffix) {
String mimeType = intent.getStringExtra(MIME_TYPE_EXTRA + extrasKeySuffix); @Nullable String mimeType = intent.getStringExtra(MIME_TYPE_EXTRA + extrasKeySuffix);
if (mimeType == null) {
// Try to use extension for backwards compatibility.
String extension = intent.getStringExtra(EXTENSION_EXTRA + extrasKeySuffix);
mimeType = inferAdaptiveStreamMimeType(uri, extension);
}
MediaItem.Builder builder = MediaItem.Builder builder =
new MediaItem.Builder() new MediaItem.Builder()
.setUri(uri) .setUri(uri)
@ -178,17 +152,15 @@ public class IntentUtil {
private static MediaItem.Builder populateDrmPropertiesFromIntent( private static MediaItem.Builder populateDrmPropertiesFromIntent(
MediaItem.Builder builder, Intent intent, String extrasKeySuffix) { MediaItem.Builder builder, Intent intent, String extrasKeySuffix) {
String schemeKey = DRM_SCHEME_EXTRA + extrasKeySuffix; String schemeKey = DRM_SCHEME_EXTRA + extrasKeySuffix;
String schemeUuidKey = DRM_SCHEME_UUID_EXTRA + extrasKeySuffix; @Nullable String drmSchemeExtra = intent.getStringExtra(schemeKey);
if (!intent.hasExtra(schemeKey) && !intent.hasExtra(schemeUuidKey)) { if (drmSchemeExtra == null) {
return builder; return builder;
} }
String drmSchemeExtra = @Nullable
intent.hasExtra(schemeKey)
? intent.getStringExtra(schemeKey)
: intent.getStringExtra(schemeUuidKey);
String[] drmSessionForClearTypesExtra = String[] drmSessionForClearTypesExtra =
intent.getStringArrayExtra(DRM_SESSION_FOR_CLEAR_TYPES_EXTRA + extrasKeySuffix); intent.getStringArrayExtra(DRM_SESSION_FOR_CLEAR_TYPES_EXTRA + extrasKeySuffix);
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
@Nullable
String[] keyRequestPropertiesArray = String[] keyRequestPropertiesArray =
intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES_EXTRA + extrasKeySuffix); intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES_EXTRA + extrasKeySuffix);
if (keyRequestPropertiesArray != null) { if (keyRequestPropertiesArray != null) {

View File

@ -443,10 +443,13 @@ public class SampleChooserActivity extends AppCompatActivity
} }
return new PlaylistHolder(title, mediaItems); return new PlaylistHolder(title, mediaItems);
} else { } else {
@Nullable
String adaptiveMimeType =
Util.getAdaptiveMimeTypeForContentType(Util.inferContentType(uri, extension));
mediaItem mediaItem
.setUri(uri) .setUri(uri)
.setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build()) .setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build())
.setMimeType(IntentUtil.inferAdaptiveStreamMimeType(uri, extension)) .setMimeType(adaptiveMimeType)
.setTag(new IntentUtil.Tag(isLive)); .setTag(new IntentUtil.Tag(isLive));
if (subtitleUri != null) { if (subtitleUri != null) {
MediaItem.Subtitle subtitle = MediaItem.Subtitle subtitle =

View File

@ -53,6 +53,7 @@ import android.view.WindowManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.C.ContentType;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
@ -1675,13 +1676,13 @@ public final class Util {
} }
/** /**
* Makes a best guess to infer the type from a {@link Uri}. * Makes a best guess to infer the {@link ContentType} from a {@link Uri}.
* *
* @param uri The {@link Uri}. * @param uri The {@link Uri}.
* @param overrideExtension If not null, used to infer the type. * @param overrideExtension If not null, used to infer the type.
* @return The content type. * @return The content type.
*/ */
@C.ContentType @ContentType
public static int inferContentType(Uri uri, @Nullable String overrideExtension) { public static int inferContentType(Uri uri, @Nullable String overrideExtension) {
return TextUtils.isEmpty(overrideExtension) return TextUtils.isEmpty(overrideExtension)
? inferContentType(uri) ? inferContentType(uri)
@ -1689,24 +1690,24 @@ public final class Util {
} }
/** /**
* Makes a best guess to infer the type from a {@link Uri}. * Makes a best guess to infer the {@link ContentType} from a {@link Uri}.
* *
* @param uri The {@link Uri}. * @param uri The {@link Uri}.
* @return The content type. * @return The content type.
*/ */
@C.ContentType @ContentType
public static int inferContentType(Uri uri) { public static int inferContentType(Uri uri) {
String path = uri.getPath(); @Nullable String path = uri.getPath();
return path == null ? C.TYPE_OTHER : inferContentType(path); return path == null ? C.TYPE_OTHER : inferContentType(path);
} }
/** /**
* Makes a best guess to infer the type from a file name. * Makes a best guess to infer the {@link ContentType} from a file name.
* *
* @param fileName Name of the file. It can include the path of the file. * @param fileName Name of the file. It can include the path of the file.
* @return The content type. * @return The content type.
*/ */
@C.ContentType @ContentType
public static int inferContentType(String fileName) { public static int inferContentType(String fileName) {
fileName = toLowerInvariant(fileName); fileName = toLowerInvariant(fileName);
if (fileName.endsWith(".mpd")) { if (fileName.endsWith(".mpd")) {
@ -1721,14 +1722,14 @@ public final class Util {
} }
/** /**
* Makes a best guess to infer the type from a {@link Uri} and MIME type. * Makes a best guess to infer the {@link ContentType} from a {@link Uri} and optional MIME type.
* *
* @param uri The {@link Uri}. * @param uri The {@link Uri}.
* @param mimeType If not null, used to infer the type. * @param mimeType If MIME type, or {@code null}.
* @return The content type. * @return The content type.
*/ */
@C.ContentType @ContentType
public static int inferContentTypeWithMimeType(Uri uri, @Nullable String mimeType) { public static int inferContentTypeForUriAndMimeType(Uri uri, @Nullable String mimeType) {
if (mimeType == null) { if (mimeType == null) {
return Util.inferContentType(uri); return Util.inferContentType(uri);
} }
@ -1744,6 +1745,25 @@ public final class Util {
} }
} }
/**
* Returns the MIME type corresponding to the given adaptive {@link ContentType}, or {@code null}
* if the content type is {@link C#TYPE_OTHER}.
*/
@Nullable
public static String getAdaptiveMimeTypeForContentType(int contentType) {
switch (contentType) {
case C.TYPE_DASH:
return MimeTypes.APPLICATION_MPD;
case C.TYPE_HLS:
return MimeTypes.APPLICATION_M3U8;
case C.TYPE_SS:
return MimeTypes.APPLICATION_SS;
case C.TYPE_OTHER:
default:
return null;
}
}
/** /**
* Returns the specified millisecond time formatted as a string. * Returns the specified millisecond time formatted as a string.
* *

View File

@ -69,7 +69,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
@Override @Override
public Downloader createDownloader(DownloadRequest request) { public Downloader createDownloader(DownloadRequest request) {
@C.ContentType @C.ContentType
int contentType = Util.inferContentTypeWithMimeType(request.uri, request.mimeType); int contentType = Util.inferContentTypeForUriAndMimeType(request.uri, request.mimeType);
switch (contentType) { switch (contentType) {
case C.TYPE_DASH: case C.TYPE_DASH:
case C.TYPE_HLS: case C.TYPE_HLS:

View File

@ -909,7 +909,8 @@ public final class DownloadHelper {
} }
private static boolean isProgressive(MediaItem.PlaybackProperties playbackProperties) { private static boolean isProgressive(MediaItem.PlaybackProperties playbackProperties) {
return Util.inferContentTypeWithMimeType(playbackProperties.uri, playbackProperties.mimeType) return Util.inferContentTypeForUriAndMimeType(
playbackProperties.uri, playbackProperties.mimeType)
== C.TYPE_OTHER; == C.TYPE_OTHER;
} }

View File

@ -74,7 +74,7 @@ public final class DownloadRequest implements Parcelable {
@Nullable byte[] keySetId, @Nullable byte[] keySetId,
@Nullable String customCacheKey, @Nullable String customCacheKey,
@Nullable byte[] data) { @Nullable byte[] data) {
@C.ContentType int contentType = Util.inferContentTypeWithMimeType(uri, mimeType); @C.ContentType int contentType = Util.inferContentTypeForUriAndMimeType(uri, mimeType);
if (contentType == C.TYPE_DASH || contentType == C.TYPE_HLS || contentType == C.TYPE_SS) { if (contentType == C.TYPE_DASH || contentType == C.TYPE_HLS || contentType == C.TYPE_SS) {
Assertions.checkArgument( Assertions.checkArgument(
customCacheKey == null, "customCacheKey must be null for type: " + contentType); customCacheKey == null, "customCacheKey must be null for type: " + contentType);

View File

@ -279,7 +279,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
Assertions.checkNotNull(mediaItem.playbackProperties); Assertions.checkNotNull(mediaItem.playbackProperties);
@C.ContentType @C.ContentType
int type = int type =
Util.inferContentTypeWithMimeType( Util.inferContentTypeForUriAndMimeType(
mediaItem.playbackProperties.uri, mediaItem.playbackProperties.mimeType); mediaItem.playbackProperties.uri, mediaItem.playbackProperties.mimeType);
@Nullable MediaSourceFactory mediaSourceFactory = mediaSourceFactories.get(type); @Nullable MediaSourceFactory mediaSourceFactory = mediaSourceFactories.get(type);
Assertions.checkNotNull( Assertions.checkNotNull(