Opt ExoPlayer out of transcoding when reading content URIs
PiperOrigin-RevId: 388260014
This commit is contained in:
parent
4013612194
commit
f329adbc23
@ -50,6 +50,7 @@
|
|||||||
* Change interface of `LoadErrorHandlingPolicy` to support configuring the
|
* Change interface of `LoadErrorHandlingPolicy` to support configuring the
|
||||||
behavior of track and location fallback. Location fallback is currently
|
behavior of track and location fallback. Location fallback is currently
|
||||||
only supported for DASH manifests with multiple base URLs.
|
only supported for DASH manifests with multiple base URLs.
|
||||||
|
* Disable platform transcoding when playing content URIs on Android 12.
|
||||||
* Remove deprecated symbols:
|
* Remove deprecated symbols:
|
||||||
* Remove `Player.getPlaybackError`. Use `Player.getPlayerError` instead.
|
* Remove `Player.getPlaybackError`. Use `Player.getPlayerError` instead.
|
||||||
* Remove `Player.getCurrentTag`. Use `Player.getCurrentMediaItem` and
|
* Remove `Player.getCurrentTag`. Use `Player.getCurrentMediaItem` and
|
||||||
|
@ -17,8 +17,8 @@ project.ext {
|
|||||||
releaseVersionCode = 2014002
|
releaseVersionCode = 2014002
|
||||||
minSdkVersion = 16
|
minSdkVersion = 16
|
||||||
appTargetSdkVersion = 29
|
appTargetSdkVersion = 29
|
||||||
targetSdkVersion = 30
|
targetSdkVersion = 31
|
||||||
compileSdkVersion = 30
|
compileSdkVersion = 31
|
||||||
dexmakerVersion = '2.28.1'
|
dexmakerVersion = '2.28.1'
|
||||||
junitVersion = '4.13.2'
|
junitVersion = '4.13.2'
|
||||||
// Use the same Guava version as the Android repo:
|
// Use the same Guava version as the Android repo:
|
||||||
|
@ -21,10 +21,18 @@ import static java.lang.Math.min;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.AssetFileDescriptor;
|
import android.content.res.AssetFileDescriptor;
|
||||||
|
import android.media.ApplicationMediaCapabilities;
|
||||||
|
import android.media.MediaFeature;
|
||||||
|
import android.media.MediaFormat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import androidx.annotation.DoNotInline;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.PlaybackException;
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -70,10 +78,17 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
|
||||||
transferInitializing(dataSpec);
|
transferInitializing(dataSpec);
|
||||||
AssetFileDescriptor assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
|
|
||||||
|
Bundle providerOptions = new Bundle();
|
||||||
|
if (Util.SDK_INT >= 31) {
|
||||||
|
Api31.disableTranscoding(providerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetFileDescriptor assetFileDescriptor =
|
||||||
|
resolver.openTypedAssetFileDescriptor(uri, /* mimeType= */ "*/*", providerOptions);
|
||||||
this.assetFileDescriptor = assetFileDescriptor;
|
this.assetFileDescriptor = assetFileDescriptor;
|
||||||
if (assetFileDescriptor == null) {
|
if (assetFileDescriptor == null) {
|
||||||
// openAssetFileDescriptor returns null if the provider recently crashed.
|
// openTypedAssetFileDescriptor returns null if the provider recently crashed.
|
||||||
throw new ContentDataSourceException(
|
throw new ContentDataSourceException(
|
||||||
new IOException("Could not open file descriptor for: " + uri),
|
new IOException("Could not open file descriptor for: " + uri),
|
||||||
PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
|
||||||
@ -205,4 +220,21 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(31)
|
||||||
|
private static final class Api31 {
|
||||||
|
|
||||||
|
@DoNotInline
|
||||||
|
public static void disableTranscoding(Bundle providerOptions) {
|
||||||
|
ApplicationMediaCapabilities mediaCapabilities =
|
||||||
|
new ApplicationMediaCapabilities.Builder()
|
||||||
|
.addSupportedVideoMimeType(MediaFormat.MIMETYPE_VIDEO_HEVC)
|
||||||
|
.addSupportedHdrType(MediaFeature.HdrType.DOLBY_VISION)
|
||||||
|
.addSupportedHdrType(MediaFeature.HdrType.HDR10)
|
||||||
|
.addSupportedHdrType(MediaFeature.HdrType.HDR10_PLUS)
|
||||||
|
.addSupportedHdrType(MediaFeature.HdrType.HLG)
|
||||||
|
.build();
|
||||||
|
providerOptions.putParcelable(MediaStore.EXTRA_MEDIA_CAPABILITIES, mediaCapabilities);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user