mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
The gain was resolved by querying the library from the media item transition callback, so the buffers the player had already begun queueing for the new track could be scaled by the previous track's gain. A quiet track followed by a hot one could clip at the boundary for as long as that query took. Carry the gain on `QueueItem` so `queueMediaItem` puts it on the `MediaItem` extras, and apply it from the item that just became current, with no library round trip. That narrows the window rather than closing it: media3 delivers `onMediaItemTransition` on the app thread after the playback thread has already rendered for that iteration, so the very first buffers after a transition can still carry the previous item's gain. The gap is now one handler hop instead of a database query. The trade-off is staleness: if a sync changes a track's gain while that track is queued, the item keeps the old value until it is rebuilt. Applying a new gain mid-track is of marginal value anyway.