mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-26 01:37:43 +00:00
Gracefully handle the missing duration field for decoded audio.
This commit is contained in:
parent
5974abee34
commit
7d9f5a4fd1
@ -108,10 +108,19 @@ class DecodedAudio {
|
|||||||
|
|
||||||
channels = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)
|
channels = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)
|
||||||
sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)
|
sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)
|
||||||
totalDuration = mediaFormat.getLong(MediaFormat.KEY_DURATION)
|
// On some old APIs (23) this field might be missing.
|
||||||
|
totalDuration = if (mediaFormat.containsKey(MediaFormat.KEY_DURATION)) {
|
||||||
|
mediaFormat.getLong(MediaFormat.KEY_DURATION)
|
||||||
|
} else {
|
||||||
|
-1L
|
||||||
|
}
|
||||||
|
|
||||||
// Expected total number of samples per channel.
|
// Expected total number of samples per channel.
|
||||||
val expectedNumSamples = ((totalDuration / 1000000f) * sampleRate + 0.5f).toInt()
|
val expectedNumSamples = if (totalDuration >= 0) {
|
||||||
|
((totalDuration / 1000000f) * sampleRate + 0.5f).toInt()
|
||||||
|
} else {
|
||||||
|
Int.MAX_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
val codec = MediaCodec.createDecoderByType(mediaFormat.getString(MediaFormat.KEY_MIME)!!)
|
val codec = MediaCodec.createDecoderByType(mediaFormat.getString(MediaFormat.KEY_MIME)!!)
|
||||||
codec.configure(mediaFormat, null, null, 0)
|
codec.configure(mediaFormat, null, null, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user