在Android中获取videoView的mediaPlayer [英] Get the mediaPlayer of the videoView in Android
问题描述
是否有可能获得对videoView使用的mediaPlayer实例的引用,最好是在其ctor内部?如果可以,怎么办?
Is it possible to get a reference to the mediaPlayer instance that the videoView is using, preferably right inside its ctor? If so, how?
由于videoView的侦听器不如mediaPlayer,因此我希望能够访问mediaPlayer以进行额外的控制和更好的事件处理.
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.
推荐答案
您可以从VideoView中监听.
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
}
});
或者,如果您仅对Media Player事件感兴趣,则可以使用其中的任何一种,这些都在VideoView上实现,而这些基本上是MediaPlayer事件.
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)
所有这些功能还将提供一个Media Player实例.
All these function will give a Media Player instance also.
这篇关于在Android中获取videoView的mediaPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!