我有简单的玩家活动:
<?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) { }
}
如果要根据需要修改setKeepScreenOn,请检查播放状态here.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。