Commit e0a9540c by ibaker Committed by bachinger

Mark MediaItem.Subtitle.mimeType as @Nullable

The MIME type is currently required to select a SubtitleDecoder
implementation in the TextRenderer. Future changes might remove this
requirement, so we pre-emptively mark the field as @Nullable.

The change in SingleSampleMediaSource ensures the track still maps to
the TextRenderer, otherwise it shows up as unmapped. Passing null MIME
type to MediaItem.Subtitle constructor now results in this from
EventLogger:

TextRenderer [
  Group:0, adaptive_supported=N/A [
    [ ] Track:0, id=null, mimeType=text/x-unknown, language=en, supported=NO_UNSUPPORTED_TYPE
  ]
]

PiperOrigin-RevId: 398010809
parent dd39513a
...@@ -1189,8 +1189,8 @@ public final class MediaItem implements Bundleable { ...@@ -1189,8 +1189,8 @@ public final class MediaItem implements Bundleable {
/** The {@link Uri} to the subtitle file. */ /** The {@link Uri} to the subtitle file. */
public final Uri uri; public final Uri uri;
/** The MIME type. */ /** The optional MIME type of the subtitle file, or {@code null} if unspecified. */
public final String mimeType; @Nullable public final String mimeType;
/** The language. */ /** The language. */
@Nullable public final String language; @Nullable public final String language;
/** The selection flags. */ /** The selection flags. */
...@@ -1261,7 +1261,7 @@ public final class MediaItem implements Bundleable { ...@@ -1261,7 +1261,7 @@ public final class MediaItem implements Bundleable {
Subtitle other = (Subtitle) obj; Subtitle other = (Subtitle) obj;
return uri.equals(other.uri) return uri.equals(other.uri)
&& mimeType.equals(other.mimeType) && Util.areEqual(mimeType, other.mimeType)
&& Util.areEqual(language, other.language) && Util.areEqual(language, other.language)
&& selectionFlags == other.selectionFlags && selectionFlags == other.selectionFlags
&& roleFlags == other.roleFlags && roleFlags == other.roleFlags
...@@ -1271,7 +1271,7 @@ public final class MediaItem implements Bundleable { ...@@ -1271,7 +1271,7 @@ public final class MediaItem implements Bundleable {
@Override @Override
public int hashCode() { public int hashCode() {
int result = uri.hashCode(); int result = uri.hashCode();
result = 31 * result + mimeType.hashCode(); result = 31 * result + (mimeType == null ? 0 : mimeType.hashCode());
result = 31 * result + (language == null ? 0 : language.hashCode()); result = 31 * result + (language == null ? 0 : language.hashCode());
result = 31 * result + selectionFlags; result = 31 * result + selectionFlags;
result = 31 * result + roleFlags; result = 31 * result + roleFlags;
......
...@@ -98,6 +98,8 @@ public final class MimeTypes { ...@@ -98,6 +98,8 @@ public final class MimeTypes {
public static final String TEXT_EXOPLAYER_CUES = BASE_TYPE_TEXT + "/x-exoplayer-cues"; public static final String TEXT_EXOPLAYER_CUES = BASE_TYPE_TEXT + "/x-exoplayer-cues";
public static final String TEXT_UNKNOWN = BASE_TYPE_TEXT + "/x-unknown";
// application/ MIME types // application/ MIME types
public static final String APPLICATION_MP4 = BASE_TYPE_APPLICATION + "/mp4"; public static final String APPLICATION_MP4 = BASE_TYPE_APPLICATION + "/mp4";
......
...@@ -381,7 +381,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { ...@@ -381,7 +381,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
mediaSources[0] = mediaSource; mediaSources[0] = mediaSource;
for (int i = 0; i < subtitles.size(); i++) { for (int i = 0; i < subtitles.size(); i++) {
if (useProgressiveMediaSourceForSubtitles if (useProgressiveMediaSourceForSubtitles
&& subtitles.get(i).mimeType.equals(MimeTypes.TEXT_VTT)) { && MimeTypes.TEXT_VTT.equals(subtitles.get(i).mimeType)) {
int index = i; int index = i;
ProgressiveMediaSource.Factory progressiveMediaSourceFactory = ProgressiveMediaSource.Factory progressiveMediaSourceFactory =
new ProgressiveMediaSource.Factory( new ProgressiveMediaSource.Factory(
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source; package com.google.android.exoplayer2.source;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.base.MoreObjects.firstNonNull;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -28,6 +29,7 @@ import com.google.android.exoplayer2.upstream.DataSpec; ...@@ -28,6 +29,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.Collections; import java.util.Collections;
/** /**
...@@ -163,7 +165,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource { ...@@ -163,7 +165,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
format = format =
new Format.Builder() new Format.Builder()
.setId(trackId) .setId(trackId)
.setSampleMimeType(subtitle.mimeType) .setSampleMimeType(firstNonNull(subtitle.mimeType, MimeTypes.TEXT_UNKNOWN))
.setLanguage(subtitle.language) .setLanguage(subtitle.language)
.setSelectionFlags(subtitle.selectionFlags) .setSelectionFlags(subtitle.selectionFlags)
.setRoleFlags(subtitle.roleFlags) .setRoleFlags(subtitle.roleFlags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment