Time passed/total time listener for video view

how to get time passed/ total time left from the video view in a listener-observer pattern? I mean, i am having a separate textview which should show passed time when video plays. i was hoping there would be some sort of listener like :

videoView.setPlaybackListener(new PlayBackListener{
      void onVideoStarted(int totalTime){/* do something*/}
      void onVideoPlaying(int timePassed, int totalTime){/* do something*/}
      void onVideoPaused(int timePassed, int totalTime){/* do something*/}
      void onVideoResumed(int timePassed, int totalTime){/* do something*/}
      void onVideoFinished(int timePassed, int totalTime){/* do something*/}
});

But there doesn’t seem to be anything like one.
I tried making a kind of onVideoPlaying(...){} , using threads, but that wasn’t success since it stopped whenever video got paused:

int count=0;
    private void startAdCheckerThread(ImaVideoView vv, AdResponse adResponse) {

        new Thread(() -> {
            while (!vv.isPlaying()) { /* do nothing, video is getting loaded*/}
            while (vv.isPlaying()) {
                onVideoPlaying(count,vv.getDuration());

                count++;
                SystemClock.sleep(1000);
            }
        }).start();

    }

    void onVideoPlaying(int timePassed, int totalTime){
        /*do stuff*/
    }

VideoView is for very trivial playback scenarios. For anything sophisticated, you should be using MediaPlayer or ExoPlayer. Between their own callbacks and your own UI controls (i.e., you already know when the media is in those five states), you should have access to all the data that you seek.

Yeah i have been dabbling with exoplayer myself, for the last few weeks. I haven’t been able to do exactly what I described above, but i believe it might be possible.
The problem is this whole issue is a part of a bigger problem regarding video ads that exoplayer doesn’t solve. But i will like the knowledge about how exoplayer is handling this. Do you have any work on exoplayer that i could check, sir?
(I can also benefit from the general knowledge of how a typical video player works, not just in terms of android’s perspective )

Nothing public, sorry.

1 Like

Hey, doesn’t videoplayer itself a combination of mediaplayer and surface view? from what i m guessing, Mediaplayer is the one doing all the downloading/decoding/encoding/rendering stuff, and surface view is just a dump output screen, rendering those bit streams sent via mediaplayer.

Do you got any resources for media player, I think i might come up with some solution , if i dig a little deeper.

Also, i have read a little bit about texture view and surface view . Don’t remember where, but i think i read some interesting lines about surface view that " it is using the internal openGL directly and is actually punching a hole in the screen to display, so it acts differently from a typical view and cannot be resized/ moved/hidden directly"
While for textureview, i read " that it acts like a surface view but also is resize-able or movable , thus giving more flexibility. But it provides lower frame rate , and if used as a video player, will often cause a lag"

Is it right for 2019? Any thoughts on this?

If by “videoplayer” you mean VideoView, then yes, VideoView is a wrapper around a MediaPlayer and a SurfaceView.

I have a bit of material on it in The Busy Coder’s Guide to Android Development, though only for audio playback. I have not done much with more sophisticated media playing, sorry.

I do not remember the details, sorry.

1 Like