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.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
@ -154,6 +157,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
private boolean sepiaSearch;
|
||||
private ActivityPeertubeBinding binding;
|
||||
private List<Comment> commentsThread;
|
||||
private BroadcastReceiver mPowerKeyReceiver = null;
|
||||
|
||||
public static void hideKeyboard(Activity activity) {
|
||||
if (activity != null && activity.getWindow() != null) {
|
||||
activity.getWindow().getDecorView();
|
||||
|
@ -162,6 +167,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
private boolean isPlayInMinimized;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -193,7 +199,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
);
|
||||
binding.videoContainer.setLayoutParams(param);
|
||||
}
|
||||
|
||||
isPlayInMinimized = false;
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
|
@ -297,6 +303,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
}else {
|
||||
playVideo();
|
||||
}
|
||||
registBroadcastReceiver();
|
||||
}
|
||||
|
||||
|
||||
|
@ -830,6 +837,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
player.setPlayWhenReady(false);
|
||||
player.release();
|
||||
}
|
||||
unregisterReceiver();
|
||||
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
|
||||
fullScreenDialog.dismiss();
|
||||
}
|
||||
|
@ -838,11 +846,48 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (player != null && !playInMinimized) {
|
||||
if (player != null && !isPlayInMinimized) {
|
||||
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)
|
||||
@Override
|
||||
|
@ -852,6 +897,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
|
||||
private void enterVideoMode() {
|
||||
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && player != null) {
|
||||
isPlayInMinimized = true;
|
||||
MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName());
|
||||
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
||||
mediaSessionConnector.setPlayer(player);
|
||||
|
@ -885,6 +931,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
} else {
|
||||
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
||||
if (onStopCalled) {
|
||||
isPlayInMinimized = false;
|
||||
finishAndRemoveTask();
|
||||
}
|
||||
}
|
||||
|
@ -900,7 +947,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
onStopCalled = false;
|
||||
if (player != null && !playInMinimized) {
|
||||
if (player != null && !player.isPlaying()) {
|
||||
player.setPlayWhenReady(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue