Skip to content

Android Animation duration cannot be negative in AndroidViewContainer.transitionToX #2616

@AndreiGorelov

Description

@AndreiGorelov

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

On Android I am seeing a crash with IllegalArgumentException: "Animation duration cannot be negative". When playback is running and the beat cursor moves, or when the user interacts with the score (scrolling playback fragment to off-screen) and alphaTab triggers cursor scroll/animation, the app sometimes crashes with:

java.lang.IllegalArgumentException: Animation duration cannot be negative
at android.view.animation.Animation.setDuration(Animation.java:466)
at alphaTab.platform.android.AndroidViewContainer.transitionToX$lambda$0(AndroidViewContainer.kt:182)
at alphaTab.platform.android.AndroidViewContainer$$ExternalSyntheticLambda1.invoke(D8$$SyntheticClass:0)
at alphaTab.platform.android.AndroidUiFacade.beginInvoke$lambda$0(AndroidUiFacade.kt:348)
at alphaTab.platform.android.AndroidUiFacade$$ExternalSyntheticLambda5.run(D8$$SyntheticClass:0)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

Expected Behavior

Even if alphaTab computes a negative duration, the android view should not crash. The animation duration probably should be clamped to non‑negative values.

Steps To Reproduce

  1. Create a simple Android app screen that hosts alphaTab
  2. Enable user interaction and cursor in settings, similar to:
val settings = alphaTab.Settings().apply {
            player.playerMode = PlayerMode.EnabledAutomatic
            player.enableCursor = true
            player.enableAnimatedBeatCursor = true
            player.enableUserInteraction = true
            player.scrollMode = ScrollMode.OffScreen
            display.scale  = 0.8
        }
  1. Load a MusicXML score
  2. Start playback
  3. Scroll the score's playing fragment to off-screen

Link to jsFiddle, CodePen, Project

No response

Version and Environment

1. alphaTab version: 1.8.1
2. Platform: Android (Kotlin)
3. Devices: Android 14/16 tablet and phone

Platform

Android (Native)

Anything else?

Possible Fix:
In my fork I fixed this by clamping the duration to at least 0 on the Android side AndreiGorelov@56cfdef

Metadata

Metadata

Assignees

Labels

area-playerRelated to the audio playback engine.platform-androidRelated to the Android specific integrationsstate-acceptedThis is a valid topic to work on.

Type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions