Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the mediaPlayer of the videoView in Android

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.

like image 883
android developer Avatar asked Jun 25 '12 08:06

android developer


People also ask

What is MediaPlayer release?

android.media.MediaPlayer. MediaPlayer class can be used to control playback of audio/video files and streams.


1 Answers

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.

like image 82
minhaz Avatar answered Oct 21 '22 17:10

minhaz