Get the mediaPlayer of the videoView in Android

*爱你&永不变心* 提交于 2019-12-21 06:58:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11185874/get-the-mediaplayer-of-the-videoview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!