mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
13debc2e9c
commit
004b37d16c
|
@ -282,7 +282,7 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
|||
if (MediaPlayerHelper.isPlaying(uri))
|
||||
MediaPlayerHelper.stopMusic(context);
|
||||
else
|
||||
MediaPlayerHelper.startMusic(context, uri,
|
||||
MediaPlayerHelper.startMusic(context, owner, uri,
|
||||
new RunnableEx("player") {
|
||||
@Override
|
||||
public void delegate() {
|
||||
|
@ -390,7 +390,6 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
|
|||
@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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue