Skip to content

Commit 4c4ba96

Browse files
committed
fix(Android): Sync recording thread start.
fixes #435
1 parent 6571dcd commit 4c4ba96

File tree

1 file changed

+8
-0
lines changed
  • record_android/android/src/main/kotlin/com/llfbandit/record/record/recorder

1 file changed

+8
-0
lines changed

record_android/android/src/main/kotlin/com/llfbandit/record/record/recorder/RecordThread.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.llfbandit.record.record.format.Format
1414
import com.llfbandit.record.record.format.OpusFormat
1515
import com.llfbandit.record.record.format.PcmFormat
1616
import com.llfbandit.record.record.format.WaveFormat
17+
import java.util.concurrent.CountDownLatch
1718
import java.util.concurrent.Executors
1819
import java.util.concurrent.Semaphore
1920
import java.util.concurrent.atomic.AtomicBoolean
@@ -84,6 +85,8 @@ class RecordThread(
8485
fun getAmplitude(): Double = mPcmReader?.getAmplitude() ?: -160.0
8586

8687
fun startRecording() {
88+
val startLatch = CountDownLatch(1)
89+
8790
mExecutorService.execute {
8891
try {
8992
val format = selectFormat()
@@ -97,6 +100,8 @@ class RecordThread(
97100

98101
recordState()
99102

103+
startLatch.countDown()
104+
100105
while (isRecording()) {
101106
if (isPaused()) {
102107
mIsPausedSem.acquire()
@@ -112,9 +117,12 @@ class RecordThread(
112117
} catch (ex: Exception) {
113118
recorderListener.onFailure(ex)
114119
} finally {
120+
startLatch.countDown()
115121
stopAndRelease()
116122
}
117123
}
124+
125+
startLatch.await()
118126
}
119127

120128
private fun stopAndRelease() {

0 commit comments

Comments
 (0)