Hi,
I keep getting this error when trying to prepare the SilcenceMediaSource in the player, it simply fails to play.
2019-07-26 12:03:45.884 4663-5805/com.yiqqi.android.yiqqi.development E/ExoPlayerImplInternal: Internal runtime error.
java.lang.IndexOutOfBoundsException: off=0, len=-741232 out of bounds (size=4096)
at java.nio.Buffer.checkBounds(Buffer.java:587)
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:285)
at com.google.android.exoplayer2.source.SilenceMediaSource$SilenceSampleStream.readData(SilenceMediaSource.java:219)
at com.google.android.exoplayer2.BaseRenderer.readSource(BaseRenderer.java:308)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:1024)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:654)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:575)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:326)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:65)
This class was created under our request and we deeply appreciate it, but it seems to have this error which makes it unusable, could you please look into it? Thank you.
Could you provide some more information on how to reproduce this error? Does it occur after seeking? I just tried playing a concatenation of some media with a SilenceMediaSource in the demo app and it worked as expected.
Yes, here's the situation, I have a timeline, which has multiple songs and with empty gaps between them, these gaps can be at the start and end as well. for that, I use ConcatenatingMediaSoruce with ClippingMediaSource for songs and SilenceMediaSource for gaps. Here's a representation of a simple timeline:
-song-song-song-
-: SilenceMediaSource
song: ClippingMediaSource with ProgressiveMediaSource
The issue is when readData happens, the byteRemaining is a negative value which shouldn't be the case, here's a debug screenshot up until the hightlighted line that produces the error:

This issue is that everytime I recreate the ConcatenatingMediaSoruce, even with the same values, with the same SilenceMediaSource durations and start positions for SilenceMediaSource and ClippingMediaSource. I sometimes get the error and sometime not. I tested with fixed constant values and recreated the ConcatenatingMediaSoruce again and again, it's like a hit and miss, works a couple of times, then error, then works again, then error again...
I'm sorry as it's hard to explain because I ran a couple of tests already and I can't seem to track down the exact source of the issue.
@shaji-Dev I tried to create a similar setup, but still wasn't able to reproduce this. It would be nice if you could share a minimal test project or a patch to the demo app. Or could you modify SilenceSampleStream.seekTo to
public void seekTo(long positionUs) {
long oldPositionBytes = positionBytes;
positionBytes = getAudioByteCount(positionUs);
Log.w("DEBUG", "seekTo " + positionUs + " position bytes " + oldPositionBytes + " -> " + positionBytes + " duration " + durationBytes, new Throwable());
}
then reproduce the issue and send us a bug report (adb bugreport)? Thanks.
Here's the bug report:
bugreport-2019-07-29-13-11-25.zip
The error appears here:

As I mentioned, it happens about once out of 5 times that I build the Media Sources, with the exact same values.
Thank you!
It looks like there is a seek to ~ 3.412 seconds in a SilenceMediaSource with duration ~ 0.418 seconds. We'll make a change to clamp the seek position to be within bounds.
Thank you for detecting the issue, do you have an estimate as to when the update will be available?
For a quick fix should I just check if the position is higher than the duration then I reset the position back to the max which is the duration?
Thank you.
Please try out the development branch and let us know if you see any other issues. Thanks.