Fix issue #9
This commit is contained in:
parent
9510678a9f
commit
52e64b6d85
|
@ -18,7 +18,10 @@ import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -154,6 +157,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
private boolean sepiaSearch;
|
private boolean sepiaSearch;
|
||||||
private ActivityPeertubeBinding binding;
|
private ActivityPeertubeBinding binding;
|
||||||
private List<Comment> commentsThread;
|
private List<Comment> commentsThread;
|
||||||
|
private BroadcastReceiver mPowerKeyReceiver = null;
|
||||||
|
|
||||||
public static void hideKeyboard(Activity activity) {
|
public static void hideKeyboard(Activity activity) {
|
||||||
if (activity != null && activity.getWindow() != null) {
|
if (activity != null && activity.getWindow() != null) {
|
||||||
activity.getWindow().getDecorView();
|
activity.getWindow().getDecorView();
|
||||||
|
@ -162,6 +167,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private boolean isPlayInMinimized;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -193,7 +199,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
);
|
);
|
||||||
binding.videoContainer.setLayoutParams(param);
|
binding.videoContainer.setLayoutParams(param);
|
||||||
}
|
}
|
||||||
|
isPlayInMinimized = false;
|
||||||
if (getSupportActionBar() != null)
|
if (getSupportActionBar() != null)
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
@ -297,6 +303,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
}else {
|
}else {
|
||||||
playVideo();
|
playVideo();
|
||||||
}
|
}
|
||||||
|
registBroadcastReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -830,6 +837,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
player.release();
|
player.release();
|
||||||
}
|
}
|
||||||
|
unregisterReceiver();
|
||||||
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
|
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
|
||||||
fullScreenDialog.dismiss();
|
fullScreenDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -838,11 +846,48 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (player != null && !playInMinimized) {
|
if (player != null && !isPlayInMinimized) {
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registBroadcastReceiver() {
|
||||||
|
final IntentFilter theFilter = new IntentFilter();
|
||||||
|
theFilter.addAction(Intent.ACTION_SCREEN_ON);
|
||||||
|
theFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
|
||||||
|
mPowerKeyReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String strAction = intent.getAction();
|
||||||
|
if (strAction.equals(Intent.ACTION_SCREEN_OFF) || strAction.equals(Intent.ACTION_SCREEN_ON)) {
|
||||||
|
if (player != null && isPlayInMinimized) {
|
||||||
|
player.setPlayWhenReady(!strAction.equals(Intent.ACTION_SCREEN_OFF));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getApplicationContext().registerReceiver(mPowerKeyReceiver, theFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterReceiver() {
|
||||||
|
int apiLevel = Build.VERSION.SDK_INT;
|
||||||
|
|
||||||
|
if (apiLevel >= 7) {
|
||||||
|
try {
|
||||||
|
getApplicationContext().unregisterReceiver(mPowerKeyReceiver);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
mPowerKeyReceiver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
getApplicationContext().unregisterReceiver(mPowerKeyReceiver);
|
||||||
|
mPowerKeyReceiver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
@Override
|
@Override
|
||||||
|
@ -852,6 +897,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
|
|
||||||
private void enterVideoMode() {
|
private void enterVideoMode() {
|
||||||
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && player != null) {
|
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && player != null) {
|
||||||
|
isPlayInMinimized = true;
|
||||||
MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName());
|
MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName());
|
||||||
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
||||||
mediaSessionConnector.setPlayer(player);
|
mediaSessionConnector.setPlayer(player);
|
||||||
|
@ -885,6 +931,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
} else {
|
} else {
|
||||||
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
||||||
if (onStopCalled) {
|
if (onStopCalled) {
|
||||||
|
isPlayInMinimized = false;
|
||||||
finishAndRemoveTask();
|
finishAndRemoveTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -900,7 +947,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
onStopCalled = false;
|
onStopCalled = false;
|
||||||
if (player != null && !playInMinimized) {
|
if (player != null && !player.isPlaying()) {
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue