mirror of
https://github.com/androidx/media.git
synced 2025-04-29 22:36:54 +08:00
Remove unnecessary SDK_INT
checks
This commit is contained in:
parent
7289764a65
commit
28edfcbb69
@ -2613,11 +2613,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||
* buffer with {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} set. False otherwise.
|
||||
*/
|
||||
private static boolean codecNeedsEosFlushWorkaround(String name) {
|
||||
return (Util.SDK_INT <= 23 && "OMX.google.vorbis.decoder".equals(name))
|
||||
|| (Util.SDK_INT == 19
|
||||
&& ("hb2000".equals(Util.DEVICE) || "stvm8".equals(Util.DEVICE))
|
||||
&& ("OMX.amlogic.avc.decoder.awesome".equals(name)
|
||||
|| "OMX.amlogic.avc.decoder.awesome.secure".equals(name)));
|
||||
return Util.SDK_INT <= 23 && "OMX.google.vorbis.decoder".equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,12 +366,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
||||
}
|
||||
}
|
||||
|
||||
if (player.isCommandAvailable(COMMAND_STOP)) {
|
||||
// We must include a cancel intent for pre-L devices.
|
||||
mediaStyle.setCancelButtonIntent(
|
||||
actionFactory.createMediaActionPendingIntent(mediaSession, COMMAND_STOP));
|
||||
}
|
||||
|
||||
long playbackStartTimeMs = getPlaybackStartTimeEpochMs(player);
|
||||
boolean displayElapsedTimeWithChronometer = playbackStartTimeMs != C.TIME_UNSET;
|
||||
builder
|
||||
|
@ -308,10 +308,9 @@ public class AudioAttributesCompat {
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
return new AudioAttributesCompat(new AudioAttributesImplApi26((AudioAttributes) aa));
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
} else {
|
||||
return new AudioAttributesCompat(new AudioAttributesImplApi21((AudioAttributes) aa));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// The rest of this file implements an approximation to AudioAttributes using old stream types
|
||||
@ -377,10 +376,8 @@ public class AudioAttributesCompat {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder();
|
||||
} else if (Build.VERSION.SDK_INT >= 26) {
|
||||
mBuilderImpl = new AudioAttributesImplApi26.Builder();
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder();
|
||||
} else {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder();
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder();
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,10 +391,8 @@ public class AudioAttributesCompat {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder(aa);
|
||||
} else if (Build.VERSION.SDK_INT >= 26) {
|
||||
mBuilderImpl = new AudioAttributesImplApi26.Builder(checkNotNull(aa.unwrap()));
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder(checkNotNull(aa.unwrap()));
|
||||
} else {
|
||||
mBuilderImpl = new AudioAttributesImplBase.Builder(aa);
|
||||
mBuilderImpl = new AudioAttributesImplApi21.Builder(checkNotNull(aa.unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ public final class LegacyParcelableUtil {
|
||||
// TODO: b/335804969 - Remove this workaround once the bug fix is in the androidx.media dependency
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T maybeApplyMediaDescriptionParcelableBugWorkaround(T value) {
|
||||
if (Util.SDK_INT < 21 || Util.SDK_INT >= 23) {
|
||||
if (Util.SDK_INT >= 23) {
|
||||
return value;
|
||||
}
|
||||
if (value instanceof android.support.v4.media.MediaBrowserCompat.MediaItem) {
|
||||
|
@ -73,6 +73,7 @@ import android.support.v4.os.ResultReceiver;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
@ -203,10 +204,8 @@ public final class MediaBrowserCompat {
|
||||
mImpl = new MediaBrowserImplApi26(context, serviceComponent, callback, rootHints);
|
||||
} else if (Build.VERSION.SDK_INT >= 23) {
|
||||
mImpl = new MediaBrowserImplApi23(context, serviceComponent, callback, rootHints);
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaBrowserImplApi21(context, serviceComponent, callback, rootHints);
|
||||
} else {
|
||||
mImpl = new MediaBrowserImplBase(context, serviceComponent, callback, rootHints);
|
||||
mImpl = new MediaBrowserImplApi21(context, serviceComponent, callback, rootHints);
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,7 +462,7 @@ public final class MediaBrowserCompat {
|
||||
*/
|
||||
@Nullable
|
||||
public static MediaItem fromMediaItem(@Nullable Object itemObj) {
|
||||
if (itemObj == null || Build.VERSION.SDK_INT < 21) {
|
||||
if (itemObj == null) {
|
||||
return null;
|
||||
}
|
||||
MediaBrowser.MediaItem itemFwk = (MediaBrowser.MediaItem) itemObj;
|
||||
@ -484,7 +483,7 @@ public final class MediaBrowserCompat {
|
||||
*/
|
||||
@Nullable
|
||||
public static List<MediaItem> fromMediaItemList(@Nullable List<?> itemList) {
|
||||
if (itemList == null || Build.VERSION.SDK_INT < 21) {
|
||||
if (itemList == null) {
|
||||
return null;
|
||||
}
|
||||
List<MediaItem> items = new ArrayList<>(itemList.size());
|
||||
@ -599,11 +598,7 @@ public final class MediaBrowserCompat {
|
||||
@Nullable ConnectionCallbackInternal mConnectionCallbackInternal;
|
||||
|
||||
public ConnectionCallback() {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
mConnectionCallbackFwk = new ConnectionCallbackApi21();
|
||||
} else {
|
||||
mConnectionCallbackFwk = null;
|
||||
}
|
||||
mConnectionCallbackFwk = new ConnectionCallbackApi21();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -676,7 +671,7 @@ public final class MediaBrowserCompat {
|
||||
|
||||
/** Callbacks for subscription related events. */
|
||||
public abstract static class SubscriptionCallback {
|
||||
@Nullable final MediaBrowser.SubscriptionCallback mSubscriptionCallbackFwk;
|
||||
@NonNull final MediaBrowser.SubscriptionCallback mSubscriptionCallbackFwk;
|
||||
final IBinder mToken;
|
||||
@Nullable WeakReference<Subscription> mSubscriptionRef;
|
||||
|
||||
@ -684,10 +679,8 @@ public final class MediaBrowserCompat {
|
||||
mToken = new Binder();
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
mSubscriptionCallbackFwk = new SubscriptionCallbackApi26();
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mSubscriptionCallbackFwk = new SubscriptionCallbackApi21();
|
||||
} else {
|
||||
mSubscriptionCallbackFwk = null;
|
||||
mSubscriptionCallbackFwk = new SubscriptionCallbackApi21();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1739,7 +1732,7 @@ public final class MediaBrowserCompat {
|
||||
if (mServiceBinderWrapper == null) {
|
||||
// TODO: When MediaBrowser is connected to framework's MediaBrowserService,
|
||||
// subscribe with options won't work properly.
|
||||
mBrowserFwk.subscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
mBrowserFwk.subscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
} else {
|
||||
try {
|
||||
mServiceBinderWrapper.addSubscription(
|
||||
@ -2087,9 +2080,9 @@ public final class MediaBrowserCompat {
|
||||
// This is to prevent ClassNotFoundException when options has Parcelable in it.
|
||||
if (mServiceBinderWrapper == null || mServiceVersion < SERVICE_VERSION_2) {
|
||||
if (options == null) {
|
||||
mBrowserFwk.subscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
mBrowserFwk.subscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
} else {
|
||||
mBrowserFwk.subscribe(parentId, options, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
mBrowserFwk.subscribe(parentId, options, callback.mSubscriptionCallbackFwk);
|
||||
}
|
||||
} else {
|
||||
super.subscribe(parentId, options, callback);
|
||||
@ -2104,7 +2097,7 @@ public final class MediaBrowserCompat {
|
||||
if (callback == null) {
|
||||
mBrowserFwk.unsubscribe(parentId);
|
||||
} else {
|
||||
mBrowserFwk.unsubscribe(parentId, checkNotNull(callback.mSubscriptionCallbackFwk));
|
||||
mBrowserFwk.unsubscribe(parentId, callback.mSubscriptionCallbackFwk);
|
||||
}
|
||||
} else {
|
||||
super.unsubscribe(parentId, callback);
|
||||
|
@ -1328,10 +1328,8 @@ public abstract class MediaBrowserServiceCompat extends Service {
|
||||
mImpl = new MediaBrowserServiceImplApi26();
|
||||
} else if (Build.VERSION.SDK_INT >= 23) {
|
||||
mImpl = new MediaBrowserServiceImplApi23();
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaBrowserServiceImplApi21();
|
||||
} else {
|
||||
mImpl = new MediaBrowserServiceImplBase();
|
||||
mImpl = new MediaBrowserServiceImplApi21();
|
||||
}
|
||||
mImpl.onCreate();
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import androidx.annotation.GuardedBy;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.RestrictTo;
|
||||
@ -142,9 +143,12 @@ public final class MediaControllerCompat {
|
||||
.getWindow()
|
||||
.getDecorView()
|
||||
.setTag(R.id.media_controller_compat_view_tag, mediaController);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
MediaControllerImplApi21.setMediaController(activity, mediaController);
|
||||
MediaController controllerFwk = null;
|
||||
if (mediaController != null) {
|
||||
Object sessionTokenObj = mediaController.getSessionToken().getToken();
|
||||
controllerFwk = new MediaController(activity, (MediaSession.Token) sessionTokenObj);
|
||||
}
|
||||
activity.setMediaController(controllerFwk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,10 +166,15 @@ public final class MediaControllerCompat {
|
||||
Object tag = activity.getWindow().getDecorView().getTag(R.id.media_controller_compat_view_tag);
|
||||
if (tag instanceof MediaControllerCompat) {
|
||||
return (MediaControllerCompat) tag;
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
return MediaControllerImplApi21.getMediaController(activity);
|
||||
} else {
|
||||
MediaController controllerFwk = activity.getMediaController();
|
||||
if (controllerFwk == null) {
|
||||
return null;
|
||||
}
|
||||
MediaSession.Token sessionTokenFwk = controllerFwk.getSessionToken();
|
||||
return new MediaControllerCompat(
|
||||
activity, MediaSessionCompat.Token.fromToken(sessionTokenFwk));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
||||
@ -221,10 +230,8 @@ public final class MediaControllerCompat {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
mImpl = new MediaControllerImplApi29(context, sessionToken);
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaControllerImplApi21(context, sessionToken);
|
||||
} else {
|
||||
mImpl = new MediaControllerImplBase(sessionToken);
|
||||
mImpl = new MediaControllerImplApi21(context, sessionToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,19 +656,14 @@ public final class MediaControllerCompat {
|
||||
* #registerCallback}
|
||||
*/
|
||||
public abstract static class Callback implements IBinder.DeathRecipient {
|
||||
@Nullable final MediaController.Callback mCallbackFwk;
|
||||
@NonNull final MediaController.Callback mCallbackFwk;
|
||||
@Nullable MessageHandler mHandler;
|
||||
@Nullable IMediaControllerCallback mIControllerCallback;
|
||||
|
||||
// Sharing this in constructor
|
||||
@SuppressWarnings({"assignment.type.incompatible", "argument.type.incompatible"})
|
||||
public Callback() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
mCallbackFwk = new MediaControllerCallbackApi21(this);
|
||||
} else {
|
||||
mCallbackFwk = null;
|
||||
mIControllerCallback = new StubCompat(this);
|
||||
}
|
||||
mCallbackFwk = new MediaControllerCallbackApi21(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2000,7 +2002,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public final void registerCallback(Callback callback, Handler handler) {
|
||||
mControllerFwk.registerCallback(checkNotNull(callback.mCallbackFwk), handler);
|
||||
mControllerFwk.registerCallback(callback.mCallbackFwk, handler);
|
||||
synchronized (mLock) {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2022,7 +2024,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public final void unregisterCallback(Callback callback) {
|
||||
mControllerFwk.unregisterCallback(checkNotNull(callback.mCallbackFwk));
|
||||
mControllerFwk.unregisterCallback(callback.mCallbackFwk);
|
||||
synchronized (mLock) {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2149,7 +2151,7 @@ public final class MediaControllerCompat {
|
||||
|
||||
@Override
|
||||
public int getRatingType() {
|
||||
if (android.os.Build.VERSION.SDK_INT < 22) {
|
||||
if (android.os.Build.VERSION.SDK_INT == 21) {
|
||||
try {
|
||||
IMediaSession extraBinder = mSessionToken.getExtraBinder();
|
||||
if (extraBinder != null) {
|
||||
@ -2302,27 +2304,6 @@ public final class MediaControllerCompat {
|
||||
mPendingCallbacks.clear();
|
||||
}
|
||||
|
||||
@SuppressWarnings("argument.type.incompatible") // Activity.setMediaController is not annotated
|
||||
static void setMediaController(Activity activity, MediaControllerCompat mediaControllerCompat) {
|
||||
MediaController controllerFwk = null;
|
||||
if (mediaControllerCompat != null) {
|
||||
Object sessionTokenObj = mediaControllerCompat.getSessionToken().getToken();
|
||||
controllerFwk = new MediaController(activity, (MediaSession.Token) sessionTokenObj);
|
||||
}
|
||||
activity.setMediaController(controllerFwk);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static MediaControllerCompat getMediaController(Activity activity) {
|
||||
MediaController controllerFwk = activity.getMediaController();
|
||||
if (controllerFwk == null) {
|
||||
return null;
|
||||
}
|
||||
MediaSession.Token sessionTokenFwk = controllerFwk.getSessionToken();
|
||||
return new MediaControllerCompat(
|
||||
activity, MediaSessionCompat.Token.fromToken(sessionTokenFwk));
|
||||
}
|
||||
|
||||
private static class ExtraBinderRequestResultReceiver extends ResultReceiver {
|
||||
private WeakReference<MediaControllerImplApi21> mMediaControllerImpl;
|
||||
|
||||
|
@ -294,18 +294,7 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
dest.writeString(mMediaId);
|
||||
TextUtils.writeToParcel(mTitle, dest, flags);
|
||||
TextUtils.writeToParcel(mSubtitle, dest, flags);
|
||||
TextUtils.writeToParcel(mDescription, dest, flags);
|
||||
dest.writeParcelable(mIcon, flags);
|
||||
dest.writeParcelable(mIconUri, flags);
|
||||
dest.writeBundle(mExtras);
|
||||
dest.writeParcelable(mMediaUri, flags);
|
||||
} else {
|
||||
((MediaDescription) getMediaDescription()).writeToParcel(dest, flags);
|
||||
}
|
||||
((MediaDescription) getMediaDescription()).writeToParcel(dest, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -365,7 +354,7 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
@Nullable
|
||||
@SuppressWarnings("deprecation")
|
||||
public static MediaDescriptionCompat fromMediaDescription(Object descriptionObj) {
|
||||
if (descriptionObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
if (descriptionObj != null) {
|
||||
Builder bob = new Builder();
|
||||
MediaDescription description = (MediaDescription) descriptionObj;
|
||||
bob.setMediaId(description.getMediaId());
|
||||
@ -416,12 +405,8 @@ public final class MediaDescriptionCompat implements Parcelable {
|
||||
new Parcelable.Creator<MediaDescriptionCompat>() {
|
||||
@Override
|
||||
public MediaDescriptionCompat createFromParcel(Parcel in) {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
return new MediaDescriptionCompat(in);
|
||||
} else {
|
||||
return checkNotNull(
|
||||
fromMediaDescription(MediaDescription.CREATOR.createFromParcel(in)));
|
||||
}
|
||||
return checkNotNull(
|
||||
fromMediaDescription(MediaDescription.CREATOR.createFromParcel(in)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,6 @@ import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.MediaMetadata;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@ -563,7 +562,7 @@ public final class MediaMetadataCompat implements Parcelable {
|
||||
*/
|
||||
@Nullable
|
||||
public static MediaMetadataCompat fromMediaMetadata(@Nullable Object metadataObj) {
|
||||
if (metadataObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
if (metadataObj != null) {
|
||||
Parcel p = Parcel.obtain();
|
||||
((MediaMetadata) metadataObj).writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
|
@ -47,7 +47,6 @@ import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Parcel;
|
||||
@ -459,26 +458,20 @@ public class MediaSessionCompat {
|
||||
Build.VERSION.SDK_INT >= 31 ? PendingIntent.FLAG_MUTABLE : 0);
|
||||
}
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29) {
|
||||
mImpl = new MediaSessionImplApi29(context, tag, session2Token, sessionInfo);
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 28) {
|
||||
mImpl = new MediaSessionImplApi28(context, tag, session2Token, sessionInfo);
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 22) {
|
||||
mImpl = new MediaSessionImplApi22(context, tag, session2Token, sessionInfo);
|
||||
} else {
|
||||
mImpl = new MediaSessionImplApi21(context, tag, session2Token, sessionInfo);
|
||||
}
|
||||
// Set default callback to respond to controllers' extra binder requests.
|
||||
Looper myLooper = Looper.myLooper();
|
||||
Handler handler = new Handler(myLooper != null ? myLooper : Looper.getMainLooper());
|
||||
setCallback(new Callback() {}, handler);
|
||||
mImpl.setMediaButtonReceiver(mbrIntent);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29) {
|
||||
mImpl = new MediaSessionImplApi29(context, tag, session2Token, sessionInfo);
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 28) {
|
||||
mImpl = new MediaSessionImplApi28(context, tag, session2Token, sessionInfo);
|
||||
} else if (android.os.Build.VERSION.SDK_INT >= 22) {
|
||||
mImpl = new MediaSessionImplApi22(context, tag, session2Token, sessionInfo);
|
||||
} else {
|
||||
mImpl =
|
||||
new MediaSessionImplApi19(
|
||||
context, tag, mbrComponent, mbrIntent, session2Token, sessionInfo);
|
||||
mImpl = new MediaSessionImplApi21(context, tag, session2Token, sessionInfo);
|
||||
}
|
||||
// Set default callback to respond to controllers' extra binder requests.
|
||||
Looper myLooper = Looper.myLooper();
|
||||
Handler handler = new Handler(myLooper != null ? myLooper : Looper.getMainLooper());
|
||||
setCallback(new Callback() {}, handler);
|
||||
mImpl.setMediaButtonReceiver(mbrIntent);
|
||||
mController = new MediaControllerCompat(context, this);
|
||||
|
||||
if (sMaxBitmapSize == 0) {
|
||||
@ -915,7 +908,7 @@ public class MediaSessionCompat {
|
||||
@Nullable
|
||||
public static MediaSessionCompat fromMediaSession(
|
||||
@Nullable Context context, @Nullable Object mediaSession) {
|
||||
if (Build.VERSION.SDK_INT < 21 || context == null || mediaSession == null) {
|
||||
if (context == null || mediaSession == null) {
|
||||
return null;
|
||||
}
|
||||
MediaSessionImpl impl;
|
||||
@ -1001,7 +994,8 @@ public class MediaSessionCompat {
|
||||
*/
|
||||
public abstract static class Callback {
|
||||
final Object mLock = new Object();
|
||||
@Nullable final MediaSession.Callback mCallbackFwk;
|
||||
@androidx.annotation.NonNull
|
||||
final MediaSession.Callback mCallbackFwk;
|
||||
private boolean mMediaPlayPausePendingOnHandler;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
@ -1013,11 +1007,7 @@ public class MediaSessionCompat {
|
||||
CallbackHandler mCallbackHandler;
|
||||
|
||||
public Callback() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
mCallbackFwk = new MediaSessionCallbackApi21();
|
||||
} else {
|
||||
mCallbackFwk = null;
|
||||
}
|
||||
mCallbackFwk = new MediaSessionCallbackApi21();
|
||||
mSessionImpl = new WeakReference<>(null);
|
||||
}
|
||||
|
||||
@ -1845,11 +1835,7 @@ public class MediaSessionCompat {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
dest.writeParcelable((Parcelable) mInner, flags);
|
||||
} else {
|
||||
dest.writeStrongBinder((IBinder) mInner);
|
||||
}
|
||||
dest.writeParcelable((Parcelable) mInner, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1963,12 +1949,7 @@ public class MediaSessionCompat {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Token createFromParcel(Parcel in) {
|
||||
Object inner;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||
inner = in.readParcelable(null);
|
||||
} else {
|
||||
inner = in.readStrongBinder();
|
||||
}
|
||||
Object inner = in.readParcelable(null);
|
||||
return new Token(checkNotNull(inner));
|
||||
}
|
||||
|
||||
@ -2048,13 +2029,11 @@ public class MediaSessionCompat {
|
||||
/**
|
||||
* Gets the underlying {@link android.media.session.MediaSession.QueueItem}.
|
||||
*
|
||||
* <p>On builds before {@link android.os.Build.VERSION_CODES#LOLLIPOP} null is returned.
|
||||
*
|
||||
* @return The underlying {@link android.media.session.MediaSession.QueueItem} or null.
|
||||
* @return The underlying {@link android.media.session.MediaSession.QueueItem}.
|
||||
*/
|
||||
@Nullable
|
||||
@androidx.annotation.NonNull
|
||||
public Object getQueueItem() {
|
||||
if (mItemFwk != null || android.os.Build.VERSION.SDK_INT < 21) {
|
||||
if (mItemFwk != null) {
|
||||
return mItemFwk;
|
||||
}
|
||||
mItemFwk =
|
||||
@ -2082,15 +2061,13 @@ public class MediaSessionCompat {
|
||||
* Creates a list of {@link QueueItem} objects from a framework {@link
|
||||
* android.media.session.MediaSession.QueueItem} object list.
|
||||
*
|
||||
* <p>This method is only supported on API 21+. On API 20 and below, it returns null.
|
||||
*
|
||||
* @param itemList A list of {@link android.media.session.MediaSession.QueueItem} objects.
|
||||
* @return An equivalent list of {@link QueueItem} objects, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<QueueItem> fromQueueItemList(
|
||||
@Nullable List<? extends @NonNull Object> itemList) {
|
||||
if (itemList == null || Build.VERSION.SDK_INT < 21) {
|
||||
if (itemList == null) {
|
||||
return null;
|
||||
}
|
||||
List<QueueItem> items = new ArrayList<>(itemList.size());
|
||||
|
@ -71,10 +71,8 @@ public final class MediaSessionManager {
|
||||
private MediaSessionManager(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
mImpl = new MediaSessionManagerImplApi28(context);
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
mImpl = new MediaSessionManagerImplApi21(context);
|
||||
} else {
|
||||
mImpl = new MediaSessionManagerImplBase(context);
|
||||
mImpl = new MediaSessionManagerImplApi21(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -847,7 +847,7 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
*/
|
||||
@Nullable
|
||||
public static PlaybackStateCompat fromPlaybackState(@Nullable Object stateObj) {
|
||||
if (stateObj != null && Build.VERSION.SDK_INT >= 21) {
|
||||
if (stateObj != null) {
|
||||
PlaybackState stateFwk = (PlaybackState) stateObj;
|
||||
List<PlaybackState.CustomAction> customActionFwks = stateFwk.getCustomActions();
|
||||
List<PlaybackStateCompat.CustomAction> customActions = null;
|
||||
@ -896,7 +896,7 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
*/
|
||||
@Nullable
|
||||
public Object getPlaybackState() {
|
||||
if (mStateFwk == null && Build.VERSION.SDK_INT >= 21) {
|
||||
if (mStateFwk == null) {
|
||||
PlaybackState.Builder builder = new PlaybackState.Builder()
|
||||
.setState(mState, mPosition, mSpeed, mUpdateTime)
|
||||
.setBufferedPosition(mBufferedPosition)
|
||||
@ -998,14 +998,12 @@ public final class PlaybackStateCompat implements Parcelable {
|
||||
* Gets the underlying framework {@link android.media.session.PlaybackState.CustomAction}
|
||||
* object.
|
||||
*
|
||||
* <p>This method is only supported on API 21+.
|
||||
*
|
||||
* @return An equivalent {@link android.media.session.PlaybackState.CustomAction} object, or
|
||||
* null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getCustomAction() {
|
||||
if (mCustomActionFwk != null || Build.VERSION.SDK_INT < 21) {
|
||||
if (mCustomActionFwk != null) {
|
||||
return mCustomActionFwk;
|
||||
}
|
||||
|
||||
|
@ -130,10 +130,8 @@ public abstract class VolumeProviderCompat {
|
||||
*/
|
||||
public final void setCurrentVolume(int currentVolume) {
|
||||
mCurrentVolume = currentVolume;
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
VolumeProvider volumeProviderFwk = (VolumeProvider) getVolumeProvider();
|
||||
volumeProviderFwk.setCurrentVolume(currentVolume);
|
||||
}
|
||||
VolumeProvider volumeProviderFwk = (VolumeProvider) getVolumeProvider();
|
||||
volumeProviderFwk.setCurrentVolume(currentVolume);
|
||||
if (mCallback != null) {
|
||||
mCallback.onVolumeChanged(this);
|
||||
}
|
||||
|
@ -237,16 +237,10 @@ import java.util.ArrayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderOutputBuffer(MediaCodecAdapter codec, int index, long presentationTimeUs) {
|
||||
skipToPositionBeforeRenderingFirstFrame = false;
|
||||
super.renderOutputBuffer(codec, index, presentationTimeUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderOutputBufferV21(
|
||||
protected void renderOutputBuffer(
|
||||
MediaCodecAdapter codec, int index, long presentationTimeUs, long releaseTimeNs) {
|
||||
skipToPositionBeforeRenderingFirstFrame = false;
|
||||
super.renderOutputBufferV21(codec, index, presentationTimeUs, releaseTimeNs);
|
||||
super.renderOutputBuffer(codec, index, presentationTimeUs, releaseTimeNs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,6 @@ import static org.hamcrest.core.IsNot.not;
|
||||
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SdkSuppress;
|
||||
import org.junit.After;
|
||||
@ -54,9 +53,6 @@ public class AudioAttributesCompatTest {
|
||||
@Before
|
||||
@SdkSuppress(minSdkVersion = 21)
|
||||
public void setUpApi21() {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
return;
|
||||
}
|
||||
mMediaAA =
|
||||
new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
|
@ -35,7 +35,6 @@ import androidx.media3.common.Format;
|
||||
import androidx.media3.common.MimeTypes;
|
||||
import androidx.media3.common.util.MediaFormatUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@ -209,7 +208,7 @@ public final class DecodeOneFrameUtil {
|
||||
// Format must not include KEY_FRAME_RATE on API21.
|
||||
// https://developer.android.com/reference/android/media/MediaCodecList#findDecoderForFormat(android.media.MediaFormat)
|
||||
float frameRate = Format.NO_VALUE;
|
||||
if (Util.SDK_INT == 21 && format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
try {
|
||||
frameRate = format.getFloat(MediaFormat.KEY_FRAME_RATE);
|
||||
} catch (ClassCastException e) {
|
||||
@ -221,9 +220,7 @@ public final class DecodeOneFrameUtil {
|
||||
|
||||
@Nullable String mediaCodecName = mediaCodecList.findDecoderForFormat(format);
|
||||
|
||||
if (Util.SDK_INT == 21) {
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
}
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
return mediaCodecName;
|
||||
}
|
||||
|
||||
|
@ -102,16 +102,15 @@ public final class ExoplayerEffectPlaybackSeekTest {
|
||||
new MediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT) {
|
||||
private int numberOfFramesRendered;
|
||||
|
||||
// Overriding V21 is sufficient as we don't have test running below API26.
|
||||
@Override
|
||||
protected void renderOutputBufferV21(
|
||||
protected void renderOutputBuffer(
|
||||
MediaCodecAdapter codec, int index, long presentationTimeUs, long releaseTimeNs) {
|
||||
numberOfFramesRendered++;
|
||||
if (numberOfFramesRendered == frameIndexToSkip) {
|
||||
frameSkippedCondition.open();
|
||||
return;
|
||||
}
|
||||
super.renderOutputBufferV21(codec, index, presentationTimeUs, releaseTimeNs);
|
||||
super.renderOutputBuffer(codec, index, presentationTimeUs, releaseTimeNs);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -313,7 +313,7 @@ public final class EncoderUtil {
|
||||
// Format must not include KEY_FRAME_RATE on API21.
|
||||
// https://developer.android.com/reference/android/media/MediaCodecList#findDecoderForFormat(android.media.MediaFormat)
|
||||
float frameRate = Format.NO_VALUE;
|
||||
if (Util.SDK_INT == 21 && format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
try {
|
||||
frameRate = format.getFloat(MediaFormat.KEY_FRAME_RATE);
|
||||
} catch (ClassCastException e) {
|
||||
@ -328,9 +328,7 @@ public final class EncoderUtil {
|
||||
? mediaCodecList.findDecoderForFormat(format)
|
||||
: mediaCodecList.findEncoderForFormat(format);
|
||||
|
||||
if (Util.SDK_INT == 21) {
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
}
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
return mediaCodecName;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.session.MediaSessionManager as ActiveSessionManager
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.os.Bundle
|
||||
import android.service.notification.NotificationListenerService
|
||||
@ -75,10 +74,7 @@ class LaunchActivity : AppCompatActivity() {
|
||||
}
|
||||
)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
||||
activeSessionListener = ActiveSessionListener()
|
||||
}
|
||||
|
||||
activeSessionListener = ActiveSessionListener()
|
||||
mediaSessionApps = mediaAppListAdapter.addSection(R.string.media_app_header_media_service)
|
||||
|
||||
val mediaAppsList: RecyclerView? = findViewById(R.id.app_list)
|
||||
@ -90,9 +86,7 @@ class LaunchActivity : AppCompatActivity() {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
||||
activeSessionListener!!.onStart()
|
||||
}
|
||||
activeSessionListener!!.onStart()
|
||||
|
||||
// Finds apps that implement MediaSessionService, MediaLibraryService, or
|
||||
// MediaBrowserServiceCompat.
|
||||
@ -102,9 +96,7 @@ class LaunchActivity : AppCompatActivity() {
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
||||
activeSessionListener!!.onStop()
|
||||
}
|
||||
activeSessionListener!!.onStop()
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user