Код: Выделить всё
private fun delayOutput() {
CoroutineScope(Dispatchers.Default).launch {
withContext(Dispatchers.IO) {
delay(2000)
while (isRecording) {
val item = if (cachedBuffers.isNotEmpty()) {
cachedBuffers.first()
} else {
null
}
if (item != null) {
var writeRes: Int? = 0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (item is ShortArray) {
writeRes = audioTrack?.write(item, 0, item.size, WRITE_NON_BLOCKING)
}
}
cachedBuffers.removeAt(0)
}
delay(100)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -no-effect
Мобильная версия