2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Only set volume to previousVolume if it has a previous value

onDestroy() would call stopPlaying(), but previousVolume would be 0 (the
default value) if startPlaying() had been never called.
This commit is contained in:
Albert Vaca
2020-01-13 17:31:33 +01:00
parent 2f4dcd1448
commit 10f94781c3

View File

@@ -57,7 +57,7 @@ public class FindMyPhonePlugin extends Plugin {
private int notificationId;
private AudioManager audioManager;
private MediaPlayer mediaPlayer;
private int previousVolume;
private int previousVolume = -1;
private PowerManager powerManager;
@Override
@@ -112,7 +112,9 @@ public class FindMyPhonePlugin extends Plugin {
@Override
public void onDestroy() {
stopPlaying();
if (mediaPlayer.isPlaying()) {
stopPlaying();
}
audioManager = null;
mediaPlayer.release();
mediaPlayer = null;
@@ -186,7 +188,9 @@ public class FindMyPhonePlugin extends Plugin {
}
void stopPlaying() {
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, previousVolume, 0);
if (previousVolume != -1) {
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, previousVolume, 0);
}
mediaPlayer.stop();
try {
mediaPlayer.prepare();