Refactoring

This commit is contained in:
M66B
2024-01-26 21:35:59 +01:00
parent 13debc2e9c
commit 004b37d16c
2 changed files with 10 additions and 3 deletions

View File

@@ -161,7 +161,7 @@ public class MediaPlayerHelper {
}
}
static void startMusic(Context context, Uri uri, Runnable onCompleted) throws IOException {
static void startMusic(Context context, LifecycleOwner owner, Uri uri, Runnable onCompleted) throws IOException {
synchronized (lock) {
stopMusic(context);
@@ -192,6 +192,14 @@ public class MediaPlayerHelper {
});
MediaPlayerHelper.player.prepareAsync();
}
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
MediaPlayerHelper.stopMusic(context);
owner.getLifecycle().removeObserver(this);
}
});
}
static void stopMusic(Context context) {