TheWidlarzGroup/react-native-video

[Bug]: 7.0.0-beta.2 - setting rate to 0 on Android causes an IllegalArgumentException

Open

#4812 aperta il 3 gen 2026

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Kotlin (3027 fork)batch import
Missing ReproNewer Version AvailablePlatform: AndroidV7bugdifficulty: easygood first issuetriaged

Metriche repository

Star
 (7677 star)
Metriche merge PR
 (Merge medio 2g 3h) (11 PR mergiate in 30 g)

Descrizione

What happened?

While migrating an app from v6 to v7, I noticed that rate can seemingly be used to pause playback, as mentioned in the docs:

if rate is = 0, it will pause video.

On iOS, the behaviour matches the docs - if the rate is set to 0 like so:

player.rate = paused ? 0 : rate

the playback is paused correctly. This is quite a nice alternative to doing something like if (paused) { player.pause() } else { player.play() }, as I'm already having to set the rate based on a user-selected option.

However, on Android, setting the rate to 0 causes an IllegalArgumentException with this partial stack trace:

java.lang.IllegalArgumentException
at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:40)
at androidx.media3.common.PlaybackParameters.<init>(PlaybackParameters.java:61)
at androidx.media3.common.PlaybackParameters.withSpeed(PlaybackParameters.java:88)
at com.margelo.nitro.video.HybridVideoPlayer.rate_delegate$lambda$13(HybridVideoPlayer.kt:181)

Looking at the native code within media3, it has this:

public PlaybackParameters(
      @FloatRange(from = 0, fromInclusive = false) float speed,
      @FloatRange(from = 0, fromInclusive = false) float pitch) {
    Assertions.checkArgument(speed > 0);
    Assertions.checkArgument(pitch > 0);
    this.speed = speed;
    this.pitch = pitch;
    scaledUsPerMs = Math.round(speed * 1000f);
  }

this seems to assert that the speed is always bigger than 0, and if it is zero or lower, the app will crash with the exception.

Open question: is it expected that rate should always be bigger than 0 (and therefore the docs need to be updated), or is rate able to be 0 to pause the video, in which case does that need to be handled within HybridVideoPlayer?

Steps to reproduce

  1. On Android, set up a VideoPlayer instance.
  2. Set player.rate = 0 (as the docs suggest, to pause playback).
  3. Observe that the app crashes with IllegalArgumentException thrown from androidx.media3.common.PlaybackParameters (via HybridVideoPlayer.rate_delegate), whereas the same code pauses correctly on iOS.

Reproduction repository

No response

react-native-video version

7.0.0-beta.2

react-native version

No response

react-native-nitro-modules version

No response

Platforms

Android

OS version

No response

Device

No response

Architecture

No response

Expo

No response

Last working version

No response

Media / source type

No response

Guida contributor