Get the mediaPlayer of the videoView in Android

14,630

you can listener from VideoView.

VideoView mVideoView=new VideoView();
mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() {
  @Override
  public void onPrepared(MediaPlayer pMp) {
   //use a global variable to get the object
  }
});

Alternatively if you are only interested on Media Player Events you can use any of these and these are implemented on VideoView and these are basically MediaPlayer events.

void    setOnCompletionListener(MediaPlayer.OnCompletionListener l)
void    setOnErrorListener(MediaPlayer.OnErrorListener l)
void    setOnInfoListener(MediaPlayer.OnInfoListener l)
void    setOnPreparedListener(MediaPlayer.OnPreparedListener l)

All these function will give a Media Player instance also.

Share:
14,630
android developer
Author by

android developer

Really like to develop Android apps & libraries on my spare time. Github website: https://github.com/AndroidDeveloperLB/ My spare time apps: https://play.google.com/store/apps/developer?id=AndroidDeveloperLB

Updated on June 06, 2022

Comments

  • android developer
    android developer about 2 years

    Is it possible to get a reference to the mediaPlayer instance that the videoView is using, preferably right inside its ctor? If so, how?

    Since the videoView doesn't have as much listeners as the mediaPlayer, I would like to have the ability to reach the mediaPlayer for extra control and better events handling.