Skip to content

Commit

Permalink
Fixed divison by zero due to duration value being rounded to 0 for au…
Browse files Browse the repository at this point in the history
…dios under 1 second length
  • Loading branch information
mschudt authored and ujas-m-simformsolutions committed Mar 5, 2024
1 parent e65649e commit 4c8cd07
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class WaveformExtractor(
) {
private var decoder: MediaCodec? = null
private var extractor: MediaExtractor? = null
private var duration = 0L
private var durationMillis = 0L
private var progress = 0F
private var currentProgress = 0F

Expand All @@ -48,7 +48,7 @@ class WaveformExtractor(
val format = mediaExtractor.getTrackFormat(it)
val mime = format.getString(MediaFormat.KEY_MIME) ?: ""
if (mime.contains("audio")) {
duration = format.getLong(MediaFormat.KEY_DURATION) / 1000000
durationMillis = format.getLong(MediaFormat.KEY_DURATION) / 1000
mediaExtractor.selectTrack(it)
return format
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class WaveformExtractor(
} else {
16
}
totalSamples = sampleRate.toLong() * duration
totalSamples = (sampleRate.toLong() * durationMillis) / 1000
perSamplePoints = totalSamples / expectedPoints
}

Expand Down

0 comments on commit 4c8cd07

Please sign in to comment.