Skip to content

Instantly share code, notes, and snippets.

@pflammertsma
Last active June 2, 2022 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pflammertsma/5a453e24938722b4218528a3e5a60259 to your computer and use it in GitHub Desktop.
Save pflammertsma/5a453e24938722b4218528a3e5a60259 to your computer and use it in GitHub Desktop.
Sample for refresh rate switching during playback
/* Copyright 2021 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
// Determine whether the transition will be seamless.
// Non-seamless transitions may cause a 1-2 second black screen.
val refreshRates = display?.mode?.alternativeRefreshRates
val willBeSeamless = Arrays.asList<FloatArray>(refreshRates).contains(newRefreshRate)
if (willBeSeamless) {
// Set the frame rate, but only if the transition will be seamless.
surface.setFrameRate(newRefreshRate,
FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS)
} else {
val prefersNonSeamless = (getSystemService(Context.DISPLAY_SERVICE) as DisplayManager)
.getMatchContentFrameRateUserPreference() == MATCH_CONTENT_FRAMERATE_ALWAYS)
if (prefersNonSeamless) {
// Show UX to inform the user that a switch is about to occur
showUxForNonSeamlessSwitchWithDelay();
// Set the frame rate if the user has requested it to match content
surface.setFrameRate(newRefreshRate,
FRAME_RATE_COMPATIBILITY_FIXED_SOURCE,
CHANGE_FRAME_RATE_ALWAYS)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment