Exoplayer - 如何在点击屏幕时只显示控制按钮
Exoplayer - How to only show control buttons when clicking screen
如何在 exoplayer 启动时隐藏这些媒体播放器控件。我只想在用户点击屏幕时显示它们。
PlayerView playerView = findViewById(R.id.player_view);
playerView.setControllerAutoShow(false);
setControllerAutoShow 在启动时不显示媒体控制按钮
像这样在 class 关卡中初始化您的播放器
private SimpleExoPlayer player;
private PlayerView playerView;
private long playbackPosition;
private int currentWindow;
private boolean playWhenReady = true;
在OnCreate
中初始化播放器
playerView = view.findViewById(R.id.video_view);
override
这个方法在你的 Activity/fragment
@Override
public void onResume()
{
super.onResume();
hideSystemUi();
if ((Util.SDK_INT <= 23 || player == null)) {
initializePlayer();
}
}
@Override
public void onPause()
{
super.onPause();
if (Util.SDK_INT <= 23) {
releasePlayer();
}
}
@Override
public void onStop()
{
super.onStop();
if (Util.SDK_INT > 23)
{
releasePlayer();
}
}
需要的方法是
private void initializePlayer()
{
if (player == null)
{
// a factory to create an AdaptiveVideoTrackSelection
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
// let the factory create a player instance with default components
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()),
new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl());
playerView.setPlayer(player);
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
}
MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash)));
player.prepare(mediaSource, true, false);
}
private void releasePlayer()
{
if (player != null)
{
playbackPosition = player.getCurrentPosition();
currentWindow = player.getCurrentWindowIndex();
playWhenReady = player.getPlayWhenReady();
player.release();
player = null;
}
}
private MediaSource buildMediaSource(Uri uri)
{
DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(
new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER));
DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua");
return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory).
createMediaSource(uri);
}
@SuppressLint("InlinedApi")
private void hideSystemUi()
{
playerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
如何在 exoplayer 启动时隐藏这些媒体播放器控件。我只想在用户点击屏幕时显示它们。
PlayerView playerView = findViewById(R.id.player_view);
playerView.setControllerAutoShow(false);
setControllerAutoShow 在启动时不显示媒体控制按钮
像这样在 class 关卡中初始化您的播放器
private SimpleExoPlayer player;
private PlayerView playerView;
private long playbackPosition;
private int currentWindow;
private boolean playWhenReady = true;
在OnCreate
中初始化播放器
playerView = view.findViewById(R.id.video_view);
override
这个方法在你的 Activity/fragment
@Override
public void onResume()
{
super.onResume();
hideSystemUi();
if ((Util.SDK_INT <= 23 || player == null)) {
initializePlayer();
}
}
@Override
public void onPause()
{
super.onPause();
if (Util.SDK_INT <= 23) {
releasePlayer();
}
}
@Override
public void onStop()
{
super.onStop();
if (Util.SDK_INT > 23)
{
releasePlayer();
}
}
需要的方法是
private void initializePlayer()
{
if (player == null)
{
// a factory to create an AdaptiveVideoTrackSelection
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
// let the factory create a player instance with default components
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()),
new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl());
playerView.setPlayer(player);
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
}
MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash)));
player.prepare(mediaSource, true, false);
}
private void releasePlayer()
{
if (player != null)
{
playbackPosition = player.getCurrentPosition();
currentWindow = player.getCurrentWindowIndex();
playWhenReady = player.getPlayWhenReady();
player.release();
player = null;
}
}
private MediaSource buildMediaSource(Uri uri)
{
DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(
new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER));
DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua");
return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory).
createMediaSource(uri);
}
@SuppressLint("InlinedApi")
private void hideSystemUi()
{
playerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}