Skip to content

Android: InterruptedException in AndroidAudioWorker.writeSamples() #2629

@AndreiGorelov

Description

@AndreiGorelov

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

AndroidAudioWorker.close() sometimes throws unhandled InterruptedException when the _writeThread is interrupted during Semaphore.acquire() in the writeSamples() loop:

java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1048)
at java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
at alphaTab.platform.android.AndroidAudioWorker.writeSamples(AndroidAudioWorker.kt:67)
at alphaTab.platform.android.AndroidAudioWorker._init_$lambda$0(AndroidAudioWorker.kt:47)
at alphaTab.platform.android.AndroidAudioWorker$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)

The problem started to appear after applying my version of the fix for issue #2621, but in my opinion the root cause is a bug in the alphaTab code — it just became exposed after applying the fix.

Expected Behavior

AndroidAudioWorker.close should cleanly terminate the _writeThread without throwing unhandled exceptions. InterruptedException from Semaphore.acquire() should be caught and handled to ensure proper cleanup.

Steps To Reproduce

  1. Create a simple Android app screen that hosts alphaTab
  2. Enable user interaction and cursor in settings, for example:
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 then close the activity (with call the AlphaTab destroy API)
  3. Sometimes the app crashes with InterruptedException in AndroidAudioWorker.writeSamples. If it does not crash, repeat steps 3–5 a few times.

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?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions