From b4110480c1a3e3897988981da774619c0ba02c41 Mon Sep 17 00:00:00 2001 From: Justin Espedal Date: Sun, 3 Jul 2022 16:56:51 +0900 Subject: [PATCH] Don't set AL.BYTE_OFFSET immediately after calling AL.sourcePlay The sourcePlay call in NativeAudioSource.play is removed, since setCurrentTime will always do that itself. Additionally, within setCurrentTime, sourcePlay was happening before setting the byte offset for non-streamed sounds. This appears to fix the problem of sounds playing the first part multiple times, described here: https://community.openfl.org/t/sounds-play-twice-on-ios/12163 --- src/lime/_internal/backend/native/NativeAudioSource.hx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lime/_internal/backend/native/NativeAudioSource.hx b/src/lime/_internal/backend/native/NativeAudioSource.hx index ee3cc8031..c67631c29 100644 --- a/src/lime/_internal/backend/native/NativeAudioSource.hx +++ b/src/lime/_internal/backend/native/NativeAudioSource.hx @@ -187,8 +187,6 @@ class NativeAudioSource { var time = completed ? 0 : getCurrentTime(); - AL.sourcePlay(handle); - setCurrentTime(time); } } @@ -417,7 +415,7 @@ class NativeAudioSource else if (parent.buffer != null) { AL.sourceRewind(handle); - if (playing) AL.sourcePlay(handle); + // AL.sourcef (handle, AL.SEC_OFFSET, (value + parent.offset) / 1000); var secondOffset = (value + parent.offset) / 1000; @@ -430,6 +428,7 @@ class NativeAudioSource var totalOffset = Std.int(dataLength * ratio); AL.sourcei(handle, AL.BYTE_OFFSET, totalOffset); + if (playing) AL.sourcePlay(handle); } }