Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class AlphaTabView : RelativeLayout {
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
_api.destroy()
super.onDetachedFromWindow()
}

private fun init(context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,28 @@ internal class AndroidAudioWorker(

private fun writeSamples() {
while (!_stopped) {
if (_track.playState == AudioTrack.PLAYSTATE_PLAYING) {
val samplesFromBuffer = _output.read(_buffer, 0, _buffer.size)
if (_previousPosition == -1) {
_previousPosition = _track.playbackHeadPosition
_track.getTimestamp(_timestamp)
try {
if (_track.playState == AudioTrack.PLAYSTATE_PLAYING) {
val samplesFromBuffer = _output.read(_buffer, 0, _buffer.size)
if (_previousPosition == -1) {
_previousPosition = _track.playbackHeadPosition
_track.getTimestamp(_timestamp)
}
_track.write(_buffer, 0, samplesFromBuffer, AudioTrack.WRITE_BLOCKING)
} else {
_playingSemaphore.acquire() // wait for playing to start
_playingSemaphore.release() // release semaphore for others
}
_track.write(_buffer, 0, samplesFromBuffer, AudioTrack.WRITE_BLOCKING)
} else {
_playingSemaphore.acquire() // wait for playing to start
_playingSemaphore.release() // release semaphore for others
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
break;
}
}
}

fun close() {
_playingSemaphore.release() // proceed thread
_stopped = true
_playingSemaphore.release() // proceed thread
_track.stop()
_writeThread!!.interrupt()
_writeThread!!.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import alphaTab.synth.IAudioExporterWorker
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.os.Handler
import android.os.Looper
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -54,6 +55,8 @@ internal class AndroidUiFacade : IUiFacade<AlphaTabView> {
private val _renderSurface: AlphaTabRenderSurface
private val _renderWrapper: RelativeLayout

private val _uiLooper:Handler;

public constructor(
outerScroll: SuspendableHorizontalScrollView,
innerScroll: SuspendableScrollView,
Expand All @@ -64,6 +67,7 @@ internal class AndroidUiFacade : IUiFacade<AlphaTabView> {
_innerScroll = innerScroll
_renderSurface = renderSurface
_renderWrapper = renderWrapper
_uiLooper = Handler(Looper.getMainLooper())

rootContainer =
AndroidRootViewContainer(outerScroll, innerScroll, renderSurface, this::beginInvoke)
Expand Down Expand Up @@ -163,7 +167,7 @@ internal class AndroidUiFacade : IUiFacade<AlphaTabView> {
}

private fun postToUIThread(action: () -> Unit) {
this._renderSurface.post(action)
_uiLooper.post(action)
}

private fun openDefaultSoundFont(): InputStream {
Expand Down
Loading