Last active
June 2, 2022 14:47
-
-
Save pflammertsma/5a453e24938722b4218528a3e5a60259 to your computer and use it in GitHub Desktop.
Sample for refresh rate switching during playback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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