Revert "Refactoring"

This reverts commit 004b37d16c.
This commit is contained in:
M66B 2024-01-27 07:50:22 +01:00
parent 004b37d16c
commit 2bbeba77ed
2 changed files with 3 additions and 10 deletions

View File

@ -282,7 +282,7 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
if (MediaPlayerHelper.isPlaying(uri)) if (MediaPlayerHelper.isPlaying(uri))
MediaPlayerHelper.stopMusic(context); MediaPlayerHelper.stopMusic(context);
else else
MediaPlayerHelper.startMusic(context, owner, uri, MediaPlayerHelper.startMusic(context, uri,
new RunnableEx("player") { new RunnableEx("player") {
@Override @Override
public void delegate() { public void delegate() {
@ -390,6 +390,7 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() { public void onDestroyed() {
Log.d(AdapterMedia.this + " parent destroyed"); Log.d(AdapterMedia.this + " parent destroyed");
MediaPlayerHelper.stopMusic(context);
AdapterMedia.this.parentFragment = null; AdapterMedia.this.parentFragment = null;
owner.getLifecycle().removeObserver(this); owner.getLifecycle().removeObserver(this);
} }

View File

@ -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) { synchronized (lock) {
stopMusic(context); stopMusic(context);
@ -192,14 +192,6 @@ public class MediaPlayerHelper {
}); });
MediaPlayerHelper.player.prepareAsync(); 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) { static void stopMusic(Context context) {