From be88143fcd3bb81b670dbf1188d7224498de9b9d Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 3 Aug 2020 16:03:15 +0100 Subject: [PATCH] Remove deprecated parts of demo app IntentUtil PiperOrigin-RevId: 324604419 --- .../android/exoplayer2/demo/IntentUtil.java | 40 +++--------------- .../demo/SampleChooserActivity.java | 5 ++- .../google/android/exoplayer2/util/Util.java | 42 ++++++++++++++----- .../offline/DefaultDownloaderFactory.java | 2 +- .../exoplayer2/offline/DownloadHelper.java | 3 +- .../exoplayer2/offline/DownloadRequest.java | 2 +- .../source/DefaultMediaSourceFactory.java | 2 +- 7 files changed, 46 insertions(+), 50 deletions(-) diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java index ccea9a5bd9..6b2f477333 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/IntentUtil.java @@ -24,7 +24,6 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.util.Assertions; -import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; import java.util.ArrayList; import java.util.Collections; @@ -63,8 +62,6 @@ public class IntentUtil { 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_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_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_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 AD_TAG_URI_EXTRA = "ad_tag_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_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"; @@ -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( Uri uri, Intent intent, String extrasKeySuffix) { - 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); - } + @Nullable String mimeType = intent.getStringExtra(MIME_TYPE_EXTRA + extrasKeySuffix); MediaItem.Builder builder = new MediaItem.Builder() .setUri(uri) @@ -178,17 +152,15 @@ public class IntentUtil { private static MediaItem.Builder populateDrmPropertiesFromIntent( MediaItem.Builder builder, Intent intent, String extrasKeySuffix) { String schemeKey = DRM_SCHEME_EXTRA + extrasKeySuffix; - String schemeUuidKey = DRM_SCHEME_UUID_EXTRA + extrasKeySuffix; - if (!intent.hasExtra(schemeKey) && !intent.hasExtra(schemeUuidKey)) { + @Nullable String drmSchemeExtra = intent.getStringExtra(schemeKey); + if (drmSchemeExtra == null) { return builder; } - String drmSchemeExtra = - intent.hasExtra(schemeKey) - ? intent.getStringExtra(schemeKey) - : intent.getStringExtra(schemeUuidKey); + @Nullable String[] drmSessionForClearTypesExtra = intent.getStringArrayExtra(DRM_SESSION_FOR_CLEAR_TYPES_EXTRA + extrasKeySuffix); Map headers = new HashMap<>(); + @Nullable String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES_EXTRA + extrasKeySuffix); if (keyRequestPropertiesArray != null) { diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java index a7b125ab6d..04e176d0ab 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java @@ -443,10 +443,13 @@ public class SampleChooserActivity extends AppCompatActivity } return new PlaylistHolder(title, mediaItems); } else { + @Nullable + String adaptiveMimeType = + Util.getAdaptiveMimeTypeForContentType(Util.inferContentType(uri, extension)); mediaItem .setUri(uri) .setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build()) - .setMimeType(IntentUtil.inferAdaptiveStreamMimeType(uri, extension)) + .setMimeType(adaptiveMimeType) .setTag(new IntentUtil.Tag(isLive)); if (subtitleUri != null) { MediaItem.Subtitle subtitle = diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java index 6b4f6d9663..2457f09bcc 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -53,6 +53,7 @@ import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.C.ContentType; import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.Format; 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 overrideExtension If not null, used to infer the type. * @return The content type. */ - @C.ContentType + @ContentType public static int inferContentType(Uri uri, @Nullable String overrideExtension) { return TextUtils.isEmpty(overrideExtension) ? 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}. * @return The content type. */ - @C.ContentType + @ContentType public static int inferContentType(Uri uri) { - String path = uri.getPath(); + @Nullable String path = uri.getPath(); 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. * @return The content type. */ - @C.ContentType + @ContentType public static int inferContentType(String fileName) { fileName = toLowerInvariant(fileName); 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 mimeType If not null, used to infer the type. + * @param mimeType If MIME type, or {@code null}. * @return The content type. */ - @C.ContentType - public static int inferContentTypeWithMimeType(Uri uri, @Nullable String mimeType) { + @ContentType + public static int inferContentTypeForUriAndMimeType(Uri uri, @Nullable String mimeType) { if (mimeType == null) { 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. * diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java index 194450a56a..365a4439a1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java @@ -69,7 +69,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory { @Override public Downloader createDownloader(DownloadRequest request) { @C.ContentType - int contentType = Util.inferContentTypeWithMimeType(request.uri, request.mimeType); + int contentType = Util.inferContentTypeForUriAndMimeType(request.uri, request.mimeType); switch (contentType) { case C.TYPE_DASH: case C.TYPE_HLS: diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java index cda674a7bf..2d373b6fb3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java @@ -909,7 +909,8 @@ public final class DownloadHelper { } private static boolean isProgressive(MediaItem.PlaybackProperties playbackProperties) { - return Util.inferContentTypeWithMimeType(playbackProperties.uri, playbackProperties.mimeType) + return Util.inferContentTypeForUriAndMimeType( + playbackProperties.uri, playbackProperties.mimeType) == C.TYPE_OTHER; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadRequest.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadRequest.java index b13e6ee767..af0f329834 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadRequest.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadRequest.java @@ -74,7 +74,7 @@ public final class DownloadRequest implements Parcelable { @Nullable byte[] keySetId, @Nullable String customCacheKey, @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) { Assertions.checkArgument( customCacheKey == null, "customCacheKey must be null for type: " + contentType); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java index 98bede87eb..0a1724dfa6 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java @@ -279,7 +279,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { Assertions.checkNotNull(mediaItem.playbackProperties); @C.ContentType int type = - Util.inferContentTypeWithMimeType( + Util.inferContentTypeForUriAndMimeType( mediaItem.playbackProperties.uri, mediaItem.playbackProperties.mimeType); @Nullable MediaSourceFactory mediaSourceFactory = mediaSourceFactories.get(type); Assertions.checkNotNull(