ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

SimpleExoPlayer getDuration some audio links are getting incorrectly

Open huangrz92 opened this issue 7 years ago • 5 comments

[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

huangrz92 avatar Jul 30 '19 03:07 huangrz92

I also found this problem in the old version 2.9.6.

huangrz92 avatar Jul 30 '19 03:07 huangrz92

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.

ojw28 avatar Jul 30 '19 15:07 ojw28

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 WavExtractor handles a seek to position=0 correctly. This needs checking. We should also check whether the test covers this.

ojw28 avatar Jul 30 '19 16:07 ojw28

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 ExtractorInput needs to be used to check for this case.

ojw28 avatar Aug 01 '19 15:08 ojw28

Fixed in the dev-v2 branch. This will be picked up in the 2.10.4 release.

ojw28 avatar Aug 01 '19 19:08 ojw28