mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
keep screen on while playing voice message
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package org.thoughtcrime.securesms.audio;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -129,6 +132,7 @@ public class AudioSlidePlayer {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
Log.d(TAG, "onPlayerStateChanged(" + playWhenReady + ", " + playbackState + ")");
|
||||
Activity activity;
|
||||
switch (playbackState) {
|
||||
case Player.STATE_READY:
|
||||
|
||||
@@ -151,6 +155,11 @@ public class AudioSlidePlayer {
|
||||
setPlaying(AudioSlidePlayer.this);
|
||||
}
|
||||
|
||||
activity = getActivity(context);
|
||||
if (activity != null) {
|
||||
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
notifyOnStart();
|
||||
progressEventHandler.sendEmptyMessage(0);
|
||||
break;
|
||||
@@ -163,6 +172,11 @@ public class AudioSlidePlayer {
|
||||
mediaPlayer = null;
|
||||
}
|
||||
|
||||
activity = getActivity(context);
|
||||
if (activity != null) {
|
||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
notifyOnStop();
|
||||
progressEventHandler.removeMessages(0);
|
||||
}
|
||||
@@ -285,6 +299,13 @@ public class AudioSlidePlayer {
|
||||
};
|
||||
}
|
||||
|
||||
private Activity getActivity(Context context) {
|
||||
if (context == null) return null;
|
||||
if (context instanceof Activity) return (Activity) context;
|
||||
if (context instanceof ContextWrapper) return getActivity(((ContextWrapper)context).getBaseContext());
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized static void setPlaying(@NonNull AudioSlidePlayer player) {
|
||||
if (playing.isPresent() && playing.get() != player) {
|
||||
playing.get().notifyOnStop();
|
||||
|
||||
Reference in New Issue
Block a user