ExoPlayer
ExoPlayer copied to clipboard
Get current MediaItem associated with frame before it's rendered
I have a custom OpenGL pipeline working in a separate thread with SurfaceTexture as input and ExoPlayer outputting into a Surface associated with the SurfaceTexture. When using ConcatenatingMediaSource I'd like to know which MediaItem is currently playing when the OpenGL pipeline receives the frame.
I've found that onMediaItemTransition lags behind actual frames rendered by several frames(due to ExoPlayer thread being a different one from the Playback thread).
I've also found that FrameMetaDataListener is the best place to get the most actual information on current state of the internal player before the frame is fed into OpenGL pipeline. I even managed to get the current Period, Timeline and eventually the Window with the MediaItem from ExoPlayerImplInternal using reflection(I know, I know).
Now the problem I'm facing is that it's not very conistent -- sometimes(not every time) when I get the period uid, the first frame(with pts=0) ExoPlayerImplInternal thinks it still plays the previous period.
Is there any other way to associate a frame with the MediaItem? I'm using the latest version of Exo at the time of writing this question - 2.18.1.
P.S.: I've tried to get MediaPeriodQueue instance using reflection and check if the current position is almost at the end of the current period and get the next period instead and it actually improves, but not solves the issue. It also seems way too hacky for production.