我有一个用于播放视频的FullScreen活动, 一切顺利,直到我点击屏幕查看系统Ui和媒体控制器,但MediaController落后于NavigationBar,它非常可怕,
请查看这些图片以了解问题:
Device1 - and MediaController Visible
并且有我的代码: MyActivity:
public class ActivityPlayVideo4 extends Activity{
public static final String KEY_VIDEO_URL = "videoUrl";
String url;
ProgressView pvLoading;
private static final boolean AUTO_HIDE = true;
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
private static final boolean TOGGLE_ON_CLICK = true;
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
private SystemUiHider mSystemUiHider;
private VideoView mVideoView;
private MediaController mMediaController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
setContentView(R.layout.activity_video_playing);
try {
url = getIntent().getExtras().getString(KEY_VIDEO_URL);
} catch (Exception e) {
url = "";
}
mVideoView = (VideoView) findViewById(R.id.videoView);
// Set up an instance of SystemUiHider to control the system UI for
// this activity.
mSystemUiHider = SystemUiHider.getInstance(this, mVideoView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (visible && AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
mVideoView.setOnCompletionListener(new PlayerOnCompleteVideo());
mMediaController = new MediaController(this,false);
mMediaController.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mMediaController);
mVideoView.requestFocus();
pvLoading = (ProgressView) findViewById(R.id.pv_loading);
pvLoading.setVisibility(View.VISIBLE);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
pvLoading.setVisibility(View.GONE);
}
});
playVideo();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
delayedHide(100);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
mSystemUiHider.hide();
}
};
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
private class PlayerOnCompleteVideo implements MediaPlayer.OnCompletionListener {
@Override
public void onCompletion(MediaPlayer mp) {
mVideoView.stopPlayback();
playVideo();
}
}
private void playVideo() {
mVideoView.setVideoURI(Uri.parse(url));
mVideoView.start();
}
}
和我的布局文件(activity_video_playing.xml):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.activity.ActivityPlayVideo4">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
>
<VideoView android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true"
android:layout_centerInParent="true"
/>
<com.rey.material.widget.ProgressView
android:id="@+id/pv_loading"
android:layout_width="48dp"
android:layout_height="48dp"
app:pv_autostart="true"
app:pv_circular="true"
app:pv_progressStyle="@style/AppProgressStyle"
app:pv_progressMode="indeterminate"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:visibility="gone"
/>
</RelativeLayout>
</FrameLayout>
任何人都可以帮助我?!?!?
答案 0 :(得分:0)
我这样做了......来自here
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if(visible){
yourMediaController.show();
//Also i generally add the actionbar here as well!
getActionBar().show();
} else {
yourMediaController.hide();
//Also i generally add the actionbar here as well!
getActionBar().hide();
}
if (visible && AUTO_HIDE) {
// Schedule a hide().
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
希望这会对你有帮助!
对于MediaController帮助==&gt;检查this