Android screen keeps waking up while playing video

PARTIAL_WAKE_LOCK : keep the CPU running, the screen and keyboard lights may be off.
SCREEN_DIM_WAKE_LOCK : keep the CPU running, allow to keep the screen display but may be gray, allow to turn off the keyboard light SCREEN_BRIGHT_WAKE_LOCK : keep the CPU
running, allow to keep the screen highlighted, allow to turn off the keyboard light
FULL_WAKE_LOCK : keep the CPU running, keep the screen highlight, The keyboard light also stays bright

Method 1 Add flag to Activity

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

The flag can be canceled after the video is played

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Method 2 Just add attributes to the top-level layout in the interface xml file:

android:keepScreenOn="true"

file path: 

getFilesDir().getPath(): /data/user/0/com.example.mediacodec/files and
"/data/data/com.example.mediacodec/file are consistent, both represent the private path of apk.

解决Only the original thread that created a view hierarchy can touch its views

The translation is: only the original thread that created the view hierarchy can operate its view

Cause:回调接口在子线程,并在回调接口对UI进行了操作

Therefore, the above prompt will appear, and this problem can be solved by using handle

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/128141850#comments_24862702
Recommended