Use Math.round(double) to avoid result being limited to Integer.MAX_INT

Issue: #8067
PiperOrigin-RevId: 337122011
This commit is contained in:
bachinger 2020-10-14 18:41:31 +01:00 committed by Oliver Woodman
parent 2371b024dd
commit 75513e581f
3 changed files with 11 additions and 2 deletions

View File

@ -78,6 +78,13 @@
([#3750](https://github.com/google/ExoPlayer/issues/3750)). ([#3750](https://github.com/google/ExoPlayer/issues/3750)).
* Add a way to override ad media MIME types * Add a way to override ad media MIME types
([#7961)(https://github.com/google/ExoPlayer/issues/7961)). ([#7961)(https://github.com/google/ExoPlayer/issues/7961)).
* Fix truncating large cue points in microseconds
([#8067](https://github.com/google/ExoPlayer/issues/8067)).
* UI:
* Show overflow button in `StyledPlayerControlView` only when there is no
enough space.
### 2.12.0 (2020-09-11) ### ### 2.12.0 (2020-09-11) ###

View File

@ -1596,7 +1596,8 @@ public final class ImaAdsLoader
// We receive initial cue points from IMA SDK as floats. This code replicates the same // We receive initial cue points from IMA SDK as floats. This code replicates the same
// calculation used to populate adGroupTimesUs (having truncated input back to float, to avoid // calculation used to populate adGroupTimesUs (having truncated input back to float, to avoid
// failures if the behavior of the IMA SDK changes to provide greater precision). // failures if the behavior of the IMA SDK changes to provide greater precision).
long adPodTimeUs = Math.round((float) cuePointTimeSeconds * C.MICROS_PER_SECOND); float cuePointTimeSecondsFloat = (float) cuePointTimeSeconds;
long adPodTimeUs = Math.round((double) cuePointTimeSecondsFloat * C.MICROS_PER_SECOND);
for (int adGroupIndex = 0; adGroupIndex < adPlaybackState.adGroupCount; adGroupIndex++) { for (int adGroupIndex = 0; adGroupIndex < adPlaybackState.adGroupCount; adGroupIndex++) {
long adGroupTimeUs = adPlaybackState.adGroupTimesUs[adGroupIndex]; long adGroupTimeUs = adPlaybackState.adGroupTimesUs[adGroupIndex];
if (adGroupTimeUs != C.TIME_END_OF_SOURCE if (adGroupTimeUs != C.TIME_END_OF_SOURCE

View File

@ -803,7 +803,8 @@ public final class ImaAdsLoaderTest {
@Test @Test
public void loadAd_withLargeAdCuePoint_updatesAdPlaybackStateWithLoadedAd() { public void loadAd_withLargeAdCuePoint_updatesAdPlaybackStateWithLoadedAd() {
float midrollTimeSecs = 1_765f; // Use a large enough value to test correct truncating of large cue points.
float midrollTimeSecs = Float.MAX_VALUE;
ImmutableList<Float> cuePoints = ImmutableList.of(midrollTimeSecs); ImmutableList<Float> cuePoints = ImmutableList.of(midrollTimeSecs);
setupPlayback(CONTENT_TIMELINE, cuePoints); setupPlayback(CONTENT_TIMELINE, cuePoints);
imaAdsLoader.start(adsLoaderListener, adViewProvider); imaAdsLoader.start(adsLoaderListener, adViewProvider);