Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42ed49a6 authored by linus_lee's avatar linus_lee
Browse files

Eleven: Fix crash when launching a song from file manager

There are some asycnhronous issues with interacting the service
This should protect it a bit better and fixes the crash for me

Change-Id: Ib50be1ca50badb83e8c206e01362a3971d050c1f
parent fdd29570
Loading
Loading
Loading
Loading
+87 −85
Original line number Diff line number Diff line
@@ -1083,7 +1083,7 @@ public class MusicPlaybackService extends Service {
        return c;
     }

    private void closeCursor() {
    private synchronized void closeCursor() {
        if (mCursor != null) {
            mCursor.close();
            mCursor = null;
@@ -2691,6 +2691,7 @@ public class MusicPlaybackService extends Service {
                return;
            }

            synchronized (service) {
                switch (msg.what) {
                    case FADEDOWN:
                        mCurrentVolume -= .05f;
@@ -2722,6 +2723,7 @@ public class MusicPlaybackService extends Service {
                        service.setNextTrack();
                        if (service.mCursor != null) {
                            service.mCursor.close();
                            service.mCursor = null;
                        }
                        service.updateCursor(service.mPlaylist.get(service.mPlayPos).mId);
                        service.notifyChange(META_CHANGED);
@@ -2777,6 +2779,7 @@ public class MusicPlaybackService extends Service {
                }
            }
        }
    }

    private static final class Shuffler {

@@ -3014,7 +3017,6 @@ public class MusicPlaybackService extends Service {
         * Releases resources associated with this MediaPlayer object.
         */
        public void release() {
            stop();
            mCurrentMediaPlayer.release();
            mSrtManager.release();
            mSrtManager = null;
+7 −10
Original line number Diff line number Diff line
@@ -61,16 +61,13 @@ public abstract class SrtManager implements Handler.Callback {
    }

    public synchronized void release() {
        reset();
        if (mHandlerThread != null) {
            mHandler.removeMessages(POST_TEXT_MSG);
            mHandler.removeCallbacks(mLoader);
            mHandler = null;
            mHandlerThread.quit();
            mHandlerThread = null;
        }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        mHandlerThread.quit();
        mHandlerThread = null;
    }

    public synchronized void initialize(final MediaPlayer player, final File f) {