From 2bbeba77edd56940cea0b80f0dc99bb5e8bd0b75 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 27 Jan 2024 07:50:22 +0100 Subject: [PATCH] Revert "Refactoring" This reverts commit 004b37d16cbacef966618cf4684bba2193d5bf24. --- app/src/main/java/eu/faircode/email/AdapterMedia.java | 3 ++- .../main/java/eu/faircode/email/MediaPlayerHelper.java | 10 +--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMedia.java b/app/src/main/java/eu/faircode/email/AdapterMedia.java index b36644bc7c..f4804ab221 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMedia.java +++ b/app/src/main/java/eu/faircode/email/AdapterMedia.java @@ -282,7 +282,7 @@ public class AdapterMedia extends RecyclerView.Adapter if (MediaPlayerHelper.isPlaying(uri)) MediaPlayerHelper.stopMusic(context); else - MediaPlayerHelper.startMusic(context, owner, uri, + MediaPlayerHelper.startMusic(context, uri, new RunnableEx("player") { @Override public void delegate() { @@ -390,6 +390,7 @@ public class AdapterMedia extends RecyclerView.Adapter @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroyed() { Log.d(AdapterMedia.this + " parent destroyed"); + MediaPlayerHelper.stopMusic(context); AdapterMedia.this.parentFragment = null; owner.getLifecycle().removeObserver(this); } diff --git a/app/src/main/java/eu/faircode/email/MediaPlayerHelper.java b/app/src/main/java/eu/faircode/email/MediaPlayerHelper.java index 3ffd0c708a..c1df73b361 100644 --- a/app/src/main/java/eu/faircode/email/MediaPlayerHelper.java +++ b/app/src/main/java/eu/faircode/email/MediaPlayerHelper.java @@ -161,7 +161,7 @@ public class MediaPlayerHelper { } } - static void startMusic(Context context, LifecycleOwner owner, Uri uri, Runnable onCompleted) throws IOException { + static void startMusic(Context context, Uri uri, Runnable onCompleted) throws IOException { synchronized (lock) { stopMusic(context); @@ -192,14 +192,6 @@ 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) {