commit
6c020889cf
|
@ -71,6 +71,7 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "VideoPlayActivity";
|
private static final String TAG = "VideoPlayActivity";
|
||||||
|
|
||||||
static boolean floatMode = false;
|
static boolean floatMode = false;
|
||||||
|
static boolean fullStop=true;
|
||||||
|
|
||||||
private static final int REQUEST_CODE = 101;
|
private static final int REQUEST_CODE = 101;
|
||||||
private BroadcastReceiver receiver;
|
private BroadcastReceiver receiver;
|
||||||
|
@ -138,6 +139,7 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
receiver = new BroadcastReceiver() {
|
receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
fullStop=true;
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
assert action != null;
|
assert action != null;
|
||||||
if (action.equals(ACTION_PAUSE)) {
|
if (action.equals(ACTION_PAUSE)) {
|
||||||
|
@ -150,11 +152,12 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equals(getString(R.string.app_background_audio))) {
|
if (action.equals(getString(R.string.app_background_audio))) {
|
||||||
unregisterReceiver(receiver);
|
safeUnregisterReceiver();
|
||||||
|
fullStop=false;
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
if (action.equals(ACTION_STOP)) {
|
if (action.equals(ACTION_STOP)) {
|
||||||
unregisterReceiver(receiver);
|
safeUnregisterReceiver();
|
||||||
finishAndRemoveTask();
|
finishAndRemoveTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +176,7 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
assert videoPlayerFragment != null;
|
assert videoPlayerFragment != null;
|
||||||
videoPlayerFragment.showControls(true);
|
videoPlayerFragment.showControls(true);
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
unregisterReceiver(receiver);
|
safeUnregisterReceiver();
|
||||||
}
|
}
|
||||||
Log.v(TAG, "switched to normal");
|
Log.v(TAG, "switched to normal");
|
||||||
floatMode = false;
|
floatMode = false;
|
||||||
|
@ -333,9 +336,13 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
getSupportFragmentManager().findFragmentById(R.id.video_player_fragment);
|
getSupportFragmentManager().findFragmentById(R.id.video_player_fragment);
|
||||||
|
|
||||||
assert videoPlayerFragment != null;
|
assert videoPlayerFragment != null;
|
||||||
videoPlayerFragment.stopVideo();
|
|
||||||
|
|
||||||
Log.v(TAG, "onStop()...");
|
Log.v(TAG, "onStop()...");
|
||||||
|
safeUnregisterReceiver();
|
||||||
|
if (fullStop) {
|
||||||
|
stopService(new Intent(this, VideoPlayerService.class));
|
||||||
|
finishAndRemoveTask();
|
||||||
|
}
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -498,5 +505,12 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
Log.e(TAG, "videoPlayerFragment is NULL");
|
Log.e(TAG, "videoPlayerFragment is NULL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void safeUnregisterReceiver()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
unregisterReceiver(receiver);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("VideoPlayerService", "attempted to unregister a nonregistered service");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue