mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Changes according to the code review
This commit is contained in:
parent
62e6455dce
commit
ecfce46296
@ -205,6 +205,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||
private final CopyOnWriteArraySet<OnScrubListener> listeners;
|
||||
private final int[] locationOnScreen;
|
||||
private final Point touchPosition;
|
||||
private final float density;
|
||||
|
||||
private int keyCountIncrement;
|
||||
private long keyTimeIncrement;
|
||||
@ -219,8 +220,6 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||
private @Nullable long[] adGroupTimesMs;
|
||||
private @Nullable boolean[] playedAdGroups;
|
||||
|
||||
private int densityDpi;
|
||||
|
||||
/** Creates a new time bar. */
|
||||
// Suppress warnings due to usage of View methods in the constructor.
|
||||
@SuppressWarnings("nullness:method.invocation.invalid")
|
||||
@ -244,7 +243,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||
// Calculate the dimensions and paints for drawn elements.
|
||||
Resources res = context.getResources();
|
||||
DisplayMetrics displayMetrics = res.getDisplayMetrics();
|
||||
densityDpi = displayMetrics.densityDpi;
|
||||
density = displayMetrics.density;
|
||||
fineScrubYThreshold = dpToPx(displayMetrics, FINE_SCRUB_Y_THRESHOLD_DP);
|
||||
int defaultBarHeight = dpToPx(displayMetrics, DEFAULT_BAR_HEIGHT_DP);
|
||||
int defaultTouchTargetHeight = dpToPx(displayMetrics, DEFAULT_TOUCH_TARGET_HEIGHT_DP);
|
||||
@ -451,8 +450,8 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeBarWidth() {
|
||||
return pxToDp(densityDpi, getWidth());
|
||||
public int getTimeBarWidthDp() {
|
||||
return pxToDp(density, getWidth());
|
||||
}
|
||||
|
||||
// View methods.
|
||||
@ -844,7 +843,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||
return (int) (dps * displayMetrics.density + 0.5f);
|
||||
}
|
||||
|
||||
private static int pxToDp(int densityDpi, int px) {
|
||||
return (int) (px / ((float) densityDpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
private static int pxToDp(float density, int px) {
|
||||
return (int) (px / density);
|
||||
}
|
||||
}
|
||||
|
@ -836,11 +836,11 @@ public class PlayerControlView extends FrameLayout {
|
||||
long delayMs;
|
||||
if (player.getPlayWhenReady() && playbackState == Player.STATE_READY) {
|
||||
float playbackSpeed = player.getPlaybackParameters().speed;
|
||||
if (playbackSpeed <= 0.1f) {
|
||||
delayMs = 1000;
|
||||
} else if (playbackSpeed <= 5f) {
|
||||
int timeBarWidth = timeBar.getTimeBarWidthDp();
|
||||
|
||||
int timeBarWidth = timeBar.getTimeBarWidth();
|
||||
if (timeBarWidth == 0 || duration == 0) {
|
||||
delayMs = MAX_UPDATE_FREQUENCY_MS;
|
||||
} else {
|
||||
// Calculate how many updates needs to be done with DEFAULT_UPDATE_DP
|
||||
// to fill up the time bar
|
||||
int numberOfUpdates = timeBarWidth / DEFAULT_UPDATE_DP;
|
||||
@ -848,13 +848,6 @@ public class PlayerControlView extends FrameLayout {
|
||||
// Calculate the designated update interval, taking duration into consideration as well
|
||||
long mediaTimeUpdatePeriodMs = duration / numberOfUpdates;
|
||||
|
||||
// Limit the designated update interval, to avoid too frequent / infrequent updates
|
||||
if (mediaTimeUpdatePeriodMs < MIN_UPDATE_FREQUENCY_MS) {
|
||||
mediaTimeUpdatePeriodMs = MIN_UPDATE_FREQUENCY_MS;
|
||||
} else if (mediaTimeUpdatePeriodMs >= MAX_UPDATE_FREQUENCY_MS) {
|
||||
mediaTimeUpdatePeriodMs = MAX_UPDATE_FREQUENCY_MS;
|
||||
}
|
||||
|
||||
// Calculate the delay needed from the current position until the next update is due
|
||||
long mediaTimeDelayMs = mediaTimeUpdatePeriodMs - (position % mediaTimeUpdatePeriodMs);
|
||||
|
||||
@ -866,11 +859,16 @@ public class PlayerControlView extends FrameLayout {
|
||||
// Calculate the delay until the next update (in real time), taking
|
||||
// playbackSpeed into consideration
|
||||
delayMs = playbackSpeed == 1 ? mediaTimeDelayMs : (long) (mediaTimeDelayMs / playbackSpeed);
|
||||
} else {
|
||||
delayMs = 200;
|
||||
|
||||
// Limit the delay if needed, to avoid too frequent / infrequent updates
|
||||
if (delayMs < MIN_UPDATE_FREQUENCY_MS) {
|
||||
delayMs = MIN_UPDATE_FREQUENCY_MS;
|
||||
} else if (delayMs >= MAX_UPDATE_FREQUENCY_MS) {
|
||||
delayMs = MAX_UPDATE_FREQUENCY_MS;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delayMs = 1000;
|
||||
delayMs = MAX_UPDATE_FREQUENCY_MS;
|
||||
}
|
||||
postDelayed(updateProgressAction, delayMs);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public interface TimeBar {
|
||||
*
|
||||
* @return Width of time bar in dps
|
||||
*/
|
||||
int getTimeBarWidth();
|
||||
int getTimeBarWidthDp();
|
||||
|
||||
/**
|
||||
* Listener for scrubbing events.
|
||||
|
Loading…
x
Reference in New Issue
Block a user