mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Merge pull request #3515 from nextcloud/issue-3325-audioutils-bug-fix
AudioUtils bug fix for media playback
This commit is contained in:
commit
866a3a971d
@ -43,7 +43,7 @@ import kotlin.math.abs
|
|||||||
object AudioUtils : DefaultLifecycleObserver {
|
object AudioUtils : DefaultLifecycleObserver {
|
||||||
private val TAG = AudioUtils::class.java.simpleName
|
private val TAG = AudioUtils::class.java.simpleName
|
||||||
private const val VALUE_10 = 10
|
private const val VALUE_10 = 10
|
||||||
private const val TIME_LIMIT = 5000
|
private const val TIME_LIMIT = 3000
|
||||||
private const val DEFAULT_SIZE = 500
|
private const val DEFAULT_SIZE = 500
|
||||||
private enum class LifeCycleFlag {
|
private enum class LifeCycleFlag {
|
||||||
PAUSED,
|
PAUSED,
|
||||||
@ -115,9 +115,8 @@ object AudioUtils : DefaultLifecycleObserver {
|
|||||||
mediaCodec.setCallback(object : MediaCodec.Callback() {
|
mediaCodec.setCallback(object : MediaCodec.Callback() {
|
||||||
private var extractor: MediaExtractor? = null
|
private var extractor: MediaExtractor? = null
|
||||||
val tempList = mutableListOf<Float>()
|
val tempList = mutableListOf<Float>()
|
||||||
override fun onInputBufferAvailable(codec: MediaCodec, index: Int) {
|
init {
|
||||||
// Setting up the extractor if not already done
|
// Setting up the extractor to be guaranteed not null
|
||||||
if (extractor == null) {
|
|
||||||
extractor = MediaExtractor()
|
extractor = MediaExtractor()
|
||||||
try {
|
try {
|
||||||
extractor!!.setDataSource(path)
|
extractor!!.setDataSource(path)
|
||||||
@ -127,9 +126,10 @@ object AudioUtils : DefaultLifecycleObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onInputBufferAvailable(codec: MediaCodec, index: Int) {
|
||||||
// Boiler plate, Extracts a buffer of encoded audio data to be sent to the codec for processing
|
// Boiler plate, Extracts a buffer of encoded audio data to be sent to the codec for processing
|
||||||
val byteBuffer = codec.getInputBuffer(index)
|
val byteBuffer = codec.getInputBuffer(index)
|
||||||
if (byteBuffer != null) {
|
if (byteBuffer != null && extractor != null) {
|
||||||
val sampleSize = extractor!!.readSampleData(byteBuffer, 0)
|
val sampleSize = extractor!!.readSampleData(byteBuffer, 0)
|
||||||
if (sampleSize > 0) {
|
if (sampleSize > 0) {
|
||||||
val isOver = !extractor!!.advance()
|
val isOver = !extractor!!.advance()
|
||||||
@ -208,9 +208,14 @@ object AudioUtils : DefaultLifecycleObserver {
|
|||||||
mediaCodec.configure(mediaFormat, null, null, 0)
|
mediaCodec.configure(mediaFormat, null, null, 0)
|
||||||
mediaCodec.start()
|
mediaCodec.start()
|
||||||
|
|
||||||
// This runs until the codec finishes or the time limit is exceeded, or an error occurs
|
// This runs until the codec finishes, the time limit is exceeded, or an error occurs
|
||||||
// If the time limit is exceed or an error occurs, the result should be null
|
// If the time limit is exceed or an error occurs, the result should be null or empty
|
||||||
while (result != null && result!!.size <= 0) {
|
var currTime = SystemClock.elapsedRealtime() - startTime
|
||||||
|
while (result != null &&
|
||||||
|
result!!.size <= 0 &&
|
||||||
|
currTime < TIME_LIMIT // Guarantees Execution stops after 3 seconds
|
||||||
|
) {
|
||||||
|
currTime = SystemClock.elapsedRealtime() - startTime
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user