2

I am streaming video from server with ExoPlayer, I want to show dialogs in specific seconds of video, so I want to listen to ExoPlayer duration and get which second is current second of playing and if it is the time that I want than stop the player and show the dialog. as the video is streaming I can't get the second with Handler, because video may stop in case of user internet low quality or maybe user change the player SeekBar and so on. so what is the solution? thank you

Mohad Hadi
  • 1,826
  • 3
  • 24
  • 39

1 Answers1

3

ExoPlayeer does not provide a progress update listener at the moment - the reason cited is that it would eat up too much CPU to keep raising progress events. See the discussion on the ExoPlayer issue tracker here:

Instead the suggestion is to build your own handler to poll the player and query the current position using player.getCurrentPosition().

This way you can control how often you want to check - e.g. every second.

This will work regardless of any streaming or buffering issues as you are checking the actual playback position rather than the status of the download.

If your problem is that you are looking for a particular point, for example time = 20 seconds, and a streaming error means that the actual playback skips from 18 seconds to 22 seconds, the usual way to counter this is to check for '>= 20 seconds' in your code.

As an aside, if you don't need to actually stop the video and you just want to display text at given time stamps in the video, then you could also you a separate captions or subtitle track.

Mick
  • 24,231
  • 1
  • 54
  • 120