我有简单的玩家活动:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.epix.presentation.player.PlayerActivity">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
当视频运行时,屏幕会变暗,我必须点击屏幕才能让它再次变亮.我已经尝试设置android:keepScreenOn =“true”,这当然没有用,因为屏幕没有关闭它只是暗淡.
有没有办法防止屏幕变暗发生?
解决方法:
希望这会对某人有所帮助.
在视频播放时设置setKeepScreenOn&仅缓冲,&当视频暂停/未播放/发生任何错误时允许屏幕进入睡眠状态.
playerView = exoPlayerLayout.findViewById(R.id.exo_player_view);
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(context),
new DefaultTrackSelector(), new DefaultLoadControl());
player.addListener(new PlayerEventListener());
PlayerEventListener
private class PlayerEventListener implements Player.EventListener {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED ||
!playWhenReady) {
playerView.setKeepScreenOn(false);
} else { // STATE_IDLE, STATE_ENDED
// This prevents the screen from getting dim/lock
playerView.setKeepScreenOn(true);
}
}
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}
@Override
public void onl oadingChanged(boolean isLoading) {}
@Override
public void onRepeatModeChanged(int repeatMode) { }
@Override
public void onPlayerError(ExoPlaybackException error) { }
@Override
public void onPositiondiscontinuity() { }
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { }
}