我正在尝试使用SimpleExoPlayerView实现全屏模式。我有这个主要使用setSystemUiVisibility。
在onCreate期间,我添加一个OnSystemUiVisibilityChange侦听器来同步隐藏播放器控件和操作栏。
@Override
public void onCreate(Bundle savedInstanceState) {
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(onSystemUiChange());
hideSystemUI();
}
在OnSystemUiVisibilityChangeListener中,我还设置了与simpleExoplayerViews超时匹配的超时,因此控件和操作栏同时被隐藏。
@NonNull
private View.OnSystemUiVisibilityChangeListener onSystemUiChange() {
return new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
mSimpleExoPlayerView.showController();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//sync the hide system ui with
//simpleExoPlayerView's auto hide timeout
hideSystemUI();
}
}, mSimpleExoPlayerView.getControllerShowTimeoutMs());
} else {
mSimpleExoPlayerView.hideController();
}
}
};
}
private void hideSystemUI() {
View rootView = findViewById(R.id.root);
rootView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
);
}
除了一种情况外,这种方法效果很好。如果在SimpleExoPlayerView控件超时之前点击屏幕然后再次点击它,则会隐藏SimpleExoPlayerView,但系统ui在超时之前不会被设置。是否有任何可以吸引的事件?
我尝试为我的根布局设置一个onClick和onTouch监听器,但这些事件没有被触发,我怀疑SimpleExoPlayerView可能会吞下它们吗?
答案 0 :(得分:3)
ExoPlayer 2.10.4拥有它。
exoplayer PlayerView有一个称为
的方法public void setControllerVisibilityListener(PlayerControlView.VisibilityListener listener) {
}
答案 1 :(得分:1)
从2.6.1开始,SimpleExoPlayerView
似乎没有任何可见性更改控件的侦听器,但PlaybackControlView
具有。但是,它存储在SimpleExoPlayerView
的私人字段中,并且没有内置的方式来访问它。要设置自己的听众,您必须:
exo_simple_player_view.xml
并确保其中包含PlaybackControlView
,然后使用findViewById
找到它,在我看来,第一个和第三个选项是最好的,但最后一个选项需要的变化最少,而且它也能很好地运行。这是一个例子:
import com.google.android.exoplayer2.ui.PlaybackControlView;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
public SomeActivity extends Activity implements PlaybackControlView.VisibilityListener {
private initExoPlayer() {
// ...
addPlaybackControlVisibilityListener(mSimpleExoPlayerView, this);
}
@Override
public void onVisibilityChange(int visibility) {
// show/hide system ui here
}
private static void addPlaybackControlVisibilityListener(SimpleExoPlayerView playerView, PlaybackControlView.VisibilityListener listener) {
PlaybackControlView playbackControlView = findPlaybackControlView(playerView);
if (playbackControlView != null)
playbackControlView.setVisibilityListener(listener);
}
private static PlaybackControlView findPlaybackControlView(ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof PlaybackControlView)
return (PlaybackControlView) child;
if (child instanceof ViewGroup) {
PlaybackControlView result = findPlaybackControlView((ViewGroup) child);
if (result != null)
return result;
}
}
return null;
}
}