Skip to content

7.0.0-beta.2 - setting rate to 0 on Android causes an IllegalArgumentException #4812

@ryanbourneuk

Description

@ryanbourneuk

I've begun moving my app from v6 to v7 to see if doing so will fix some performance related issues, and noticed that rate can seemingly be used to pause playback, as mentioned in the docs here:

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.

My question is - 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?

Version: 7.0.0-beta.2
Platform: Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions