mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +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:
@@ -57,7 +57,7 @@ public class FindMyPhonePlugin extends Plugin {
|
|||||||
private int notificationId;
|
private int notificationId;
|
||||||
private AudioManager audioManager;
|
private AudioManager audioManager;
|
||||||
private MediaPlayer mediaPlayer;
|
private MediaPlayer mediaPlayer;
|
||||||
private int previousVolume;
|
private int previousVolume = -1;
|
||||||
private PowerManager powerManager;
|
private PowerManager powerManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,7 +112,9 @@ public class FindMyPhonePlugin extends Plugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
stopPlaying();
|
if (mediaPlayer.isPlaying()) {
|
||||||
|
stopPlaying();
|
||||||
|
}
|
||||||
audioManager = null;
|
audioManager = null;
|
||||||
mediaPlayer.release();
|
mediaPlayer.release();
|
||||||
mediaPlayer = null;
|
mediaPlayer = null;
|
||||||
@@ -186,7 +188,9 @@ public class FindMyPhonePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stopPlaying() {
|
void stopPlaying() {
|
||||||
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, previousVolume, 0);
|
if (previousVolume != -1) {
|
||||||
|
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, previousVolume, 0);
|
||||||
|
}
|
||||||
mediaPlayer.stop();
|
mediaPlayer.stop();
|
||||||
try {
|
try {
|
||||||
mediaPlayer.prepare();
|
mediaPlayer.prepare();
|
||||||
|
Reference in New Issue
Block a user