SimpleExoPlayer getDuration some audio links are getting incorrectly
[REQUIRED] Issue description
Hello, I found that using simpleExoPlayer.duration, In some audio links, the total duration of playback is incorrect.
For example, a song that takes a total of 2 minutes, but can only play for one minute.
[REQUIRED] Reproduction steps
Use https://pro-audio.xiaoheiban.cn/201907/0fd5f017-cafe-4dfd-9f69-3a06cf4e2651.wav audio link
val url = "https://pro-audio.xiaoheiban.cn/201907/0fd5f017-cafe-4dfd-9f69-3a06cf4e2651.wav"
val mediaMetadataCompat = MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "METADATA_KEY_MEDIA_ID")
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, "METADATA_KEY_TITLE")
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_URI, url)
.build()
mediaMetadataCompat.description.extras?.putAll(mediaMetadataCompat.bundle)
val extractorMediaSource = ExtractorMediaSource.Factory(factory)
.setTag(mediaMetadataCompat.description)
.createMediaSource(Uri.parse(url))
val concatenatingMediaSource = ConcatenatingMediaSource()
concatenatingMediaSource.addMediaSource(extractorMediaSource)
simpleExoPlayer.prepare(concatenatingMediaSource)
simpleExoPlayer.seekTo(0, 0)
When the music is playing, the total length of the music is found to be wrong.
val duration = simpleExoPlayer.duration
[REQUIRED] Version of ExoPlayer being used
com.google.android.exoplayer:exoplayer:2.10.3
com.google.android.exoplayer:exoplayer-ui:2.10.3
com.google.android.exoplayer:extension-mediasession:2.10.3
I also found this problem in the old version 2.9.6.
Looking at this spec and what's in the file, it appears Subchunk2Size is incorrect in the file (i.e. it specifies a size for the sound data that's larger than the total size of the file).
We can add a check that'll clip the size to the end of the file. The media does seem to be broken though. If this is your media, you should fix it.
Notes:
- The RIFF chunk descriptor contains the file length, so we can use that rather than relying on the length from the
ExtractorInput. - It's unclear whether
WavExtractorhandles a seek toposition=0correctly. This needs checking. We should also check whether the test covers this.
Notes:
- The RIFF chunk descriptor file length is also incorrect in this file. I think what probably happened is that a valid 2 minute long WAV file was generated, and then the file was clipped to just keep the first half. The length of the
ExtractorInputneeds to be used to check for this case.
Fixed in the dev-v2 branch. This will be picked up in the 2.10.4 release.