public void show(int timeout) {異步
if (!mShowing) {ide
top_framelayout.setVisibility(View.VISIBLE);spa
bottom_framelayout.setVisibility(View.VISIBLE);視頻
mShowing = true;rem
}源碼
if (timeout != 0) {it
Message msg = mHandler.obtainMessage(FADE_OUT);io
mHandler.removeMessages(FADE_OUT);event
mHandler.sendMessageDelayed(msg, timeout);class
}
}
public void hide() {
if (mShowing) {
top_framelayout.setVisibility(View.GONE);
bottom_framelayout.setVisibility(View.GONE);
mShowing = false;
}
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case FADE_OUT:
hide();
break;
}
}
};
private void toggleMediaControlsVisiblity() {
if (mShowing) {
hide();
} else {
show(sDefaultTimeout);
}
}
// 手勢類
public class MySimpleOnGestureListener extends SimpleOnGestureListener {
@Override
public boolean onSingleTapUp(MotionEvent e) {
toggleMediaControlsVisiblity();
return super.onSingleTapUp(e);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
以上實現方式參考了:VideoView源碼及其MediaController的源碼。
二、
使用MediaPlayer視頻播放的時候,直接把拖動條拖動到最後,而後再往回拖動,這時奇葩的事情發生了:視頻界面更換了,可是不能播放了,這是怎麼回事呢?用VideoView就不會出現這個問題。差距在哪裏?
關於點擊seekbar能夠看到畫面可是不能播放的問題, 我認爲你使用seekto是須要爲mediaPlayer添加OnSeekCompleteListener,由於seekto是個異步方法
mediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
public void onSeekComplete(MediaPlayer m) {
m.start();
//isPlaying = true;
}
});