mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Disable double-click detection for TV apps
Issue: androidx/media#962 PiperOrigin-RevId: 598876214
This commit is contained in:
parent
27c021fd7b
commit
2c8ba50524
2 changed files with 18 additions and 3 deletions
|
|
@ -32,6 +32,8 @@
|
|||
* Muxers:
|
||||
* IMA extension:
|
||||
* Session:
|
||||
* Disable double-click detection for TV apps
|
||||
([#962](https://github.com/androidx/media/issues/962)).
|
||||
* UI:
|
||||
* Downloads:
|
||||
* OkHttp Extension:
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import android.app.PendingIntent;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.DeadObjectException;
|
||||
|
|
@ -53,9 +54,11 @@ import android.support.v4.media.session.MediaSessionCompat;
|
|||
import android.view.KeyEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.DoNotInline;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.GuardedBy;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.media.MediaBrowserServiceCompat;
|
||||
import androidx.media3.common.AudioAttributes;
|
||||
import androidx.media3.common.DeviceInfo;
|
||||
|
|
@ -1123,14 +1126,16 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
}
|
||||
// Double tap detection.
|
||||
int keyCode = keyEvent.getKeyCode();
|
||||
boolean isTvApp = Util.SDK_INT >= 21 && Api21.isTvApp(context);
|
||||
boolean doubleTapCompleted = false;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
if (callerInfo.getControllerVersion() != ControllerInfo.LEGACY_CONTROLLER_VERSION
|
||||
if (isTvApp
|
||||
|| callerInfo.getControllerVersion() != ControllerInfo.LEGACY_CONTROLLER_VERSION
|
||||
|| keyEvent.getRepeatCount() != 0) {
|
||||
// Double tap detection is only for media button events from external sources
|
||||
// (for instance Bluetooth) and excluding long press (repeatCount > 0).
|
||||
// Double tap detection is only for mobile apps that receive a media button event from
|
||||
// external sources (for instance Bluetooth) and excluding long press (repeatCount > 0).
|
||||
mediaPlayPauseKeyHandler.flush();
|
||||
} else if (mediaPlayPauseKeyHandler.hasPendingPlayPauseTask()) {
|
||||
// A double tap arrived. Clear the pending playPause task.
|
||||
|
|
@ -1817,4 +1822,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(21)
|
||||
private static final class Api21 {
|
||||
@DoNotInline
|
||||
public static boolean isTvApp(Context context) {
|
||||
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue