Hi Andy,
If I understand correctly, you want us to clear out some of the buffered data ahead of the playhead when we upgrade to a higher quality stream. We used to do this, but it did not work well across browsers. On some browsers, we needed hacky work-arounds to avoid visual glitches, and on others, it seemed that it was not possible to avoid them at all. The only solution we found was simply not to remove buffered data ahead of the playhead. (There seems to be no issue removing buffered data behind the playhead, which we still do to manage memory usage.)
To optimize your preloading experience, there are some things you can do.
First, you should understand that it typically takes around 2 segments for us to build a good bandwidth estimate. That means that for content with 10-second segments, Shaka Player will buffer 20-30 seconds at the "default" bandwidth estimate before it adapts. If you are preloading anyway, you may want to tweak that default so that you're preloading higher quality content. To do this, use player.configure({ abr: { defaultBandwidthEstimate: bitsPerSecond }})
If you can still make changes to the content itself, consider using smaller segments. We found that 4-second segments are a good balance between container overhead (lower with larger segments) and adaptation (quicker with smaller segments). With 4-second segments, we can typically make an adaptation decision after only 8 seconds of content has been fetched.
You can also tweak the buffering goal with player.configure({ streaming: { bufferingGoal: goalInSeconds }}). You may want a small buffering goal to keep Shaka Player from making decisions about content too far in the future.
One last thing you can do is persist the user's bandwidth estimate from one session to the next. Use player.getConfiguration().abr.manager.getBandwidthEstimate() to query the current bandwidth estimate, then persist that for the next video or next application session. When the page loads, check for this persisted value and use it to set defaultBandwidthEstimate.
Does this help?
-Joey