gpt4 book ai didi

android - Exoplayer 2 防止视频播放时屏幕变暗

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:10:16 24 4
gpt4 key购买 nike

我有简单的播放器 Activity :

<?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());

播放器事件监听器

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_READY, STATE_BUFFERING
// 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 onLoadingChanged(boolean isLoading) {}

@Override
public void onRepeatModeChanged(int repeatMode) { }

@Override
public void onPlayerError(ExoPlaybackException error) { }

@Override
public void onPositionDiscontinuity() { }

@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { }
}

检查播放状态here , 如果您想根据需要修改 setKeepScreenOn

关于android - Exoplayer 2 防止视频播放时屏幕变暗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49657683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com