mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add public API for isWear check in media3-common.
PiperOrigin-RevId: 541925117
This commit is contained in:
parent
b9cc70d9e2
commit
63ca2595be
@ -2687,6 +2687,18 @@ public final class Util {
|
|||||||
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the app is running on a Wear OS device.
|
||||||
|
*
|
||||||
|
* @param context Any context.
|
||||||
|
* @return Whether the app is running on a Wear OS device.
|
||||||
|
*/
|
||||||
|
@UnstableApi
|
||||||
|
public static boolean isWear(Context context) {
|
||||||
|
return SDK_INT >= 20
|
||||||
|
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the size of the current mode of the default display, in pixels.
|
* Gets the size of the current mode of the default display, in pixels.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +40,6 @@ import static java.lang.Math.min;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.media.AudioDeviceCallback;
|
import android.media.AudioDeviceCallback;
|
||||||
@ -3324,7 +3323,7 @@ import java.util.concurrent.TimeoutException;
|
|||||||
|
|
||||||
public static boolean isSuitableAudioOutputPresentInAudioDeviceInfoList(
|
public static boolean isSuitableAudioOutputPresentInAudioDeviceInfoList(
|
||||||
Context context, AudioDeviceInfo[] audioDeviceInfos) {
|
Context context, AudioDeviceInfo[] audioDeviceInfos) {
|
||||||
if (!isRunningOnWear(context)) {
|
if (!Util.isWear(context)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (AudioDeviceInfo device : audioDeviceInfos) {
|
for (AudioDeviceInfo device : audioDeviceInfos) {
|
||||||
@ -3353,11 +3352,6 @@ import java.util.concurrent.TimeoutException;
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRunningOnWear(Context context) {
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
import androidx.media3.common.Player.Events;
|
import androidx.media3.common.Player.Events;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
import androidx.media3.common.util.Util;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +97,7 @@ public final class WearUnsuitableOutputPlaybackSuppressionResolverListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvents(Player player, Events events) {
|
public void onEvents(Player player, Events events) {
|
||||||
if (!isRunningOnWear(applicationContext)) {
|
if (!Util.isWear(applicationContext)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)
|
if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)
|
||||||
@ -160,9 +161,4 @@ public final class WearUnsuitableOutputPlaybackSuppressionResolverListener
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRunningOnWear(Context context) {
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user