How to determine when VideoView starts playing (Android)?

Here's the problem, I want to change the play button so that the pause button when the video stream starts playing in the video ad, but I don’t know how to identify this event?

+8
source share
7 answers

I ended up using VideoView.setOnPreparedListener. This was enough to cover my problem (play button with the ability to turn on pause)

+11
source

There is a great article about MediaPlayer here - http://www.malmstein.com/blog/2014/08/09/how-to-use-a-textureview-to-display-a-video-with-custom-media-player -controls /

You can set infoListener to your VideoView

setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) { // Here the video starts return true; } return false; } 
+12
source

the accepted answer here is not 100% accurate.

sometimes onprepared - call 3 seconds before rendering the first frame. I suggest making a callback on this event (MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START)

 mMediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mediaPlayer, int i, int i1) { if (i == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START){ //first frame was bufered - do your stuff here } return false; } }); 

see media information documentation for additional info / warning callbacks: https://developer.android.com/reference/android/media/MediaPlayer.html#MEDIA_INFO_VIDEO_RENDERING_START

+5
source

As far as I know, in VideoView there is no event dispatched when the video started, but I can present two options:

  • Create a version of VideoView yourself by sending an event in these cases.
  • Use MediaController (which is used by default in VideoView)

If you want to follow the first option - you can get here VideoView

+1
source

isPlaying () can be called to check if the MediaPlayer is in Started

Android MediaPlayer.isPlaying ()

-one
source

Another way to determine if a video is triggered is to use videoView.getCurrentPosition (). getCurrentPosition () returns 0 if streaming is not running.

  protected Runnable playingCheck = new Runnable() { public void run() { while (true) { if (vw.getCurrentPosition() != 0) { // do what you want when playing started break; } else { try { Thread.sleep(250); } catch (InterruptedException e) { e.printStackTrace(); } } } } }; 

Then call:

 new Thread(playingCheck).start(); 
-one
source

Please try the following:

 final Handler h = new Handler(); h.postDelayed( new Runnable() { public void run() { if (videoView.getCurrentPosition() != 0) { ((ProgressBar) rootView.findViewById(R.id.pgStreaming)).setVisibility(View.GONE); } else { h.postDelayed(this, 250); } } }, 250); 
-one
source

All Articles