smithdtyler / prettygoodmusicplayer

A music player app for Android hits the basics hard
GNU General Public License v3.0
52 stars 23 forks source link

Switches from "pause mode" to "play mode" on notification/phone call #94

Closed gryzor2 closed 9 years ago

gryzor2 commented 9 years ago

This issue started occuring recently on my phone. The misbehaviour occurs on 3.2.11, not on 3.2.10 (I downgraded and tested). My Phone runs cyanogenmod 11.0.0 M12 (i9300).

The problem occurs when Pretty Good Music Player is running, and a song is paused. If the phone receives a notification (k9 receives an email), or an incoming phone call, or a SMS, then Pretty Good Music Player unpauses the song and starts playing by itself. It seems to reproduce everytime.

Turnarounds : never pause a song, quit the application instead. Or stay with 3.2.10.

Regards,

Vincent

smithdtyler commented 9 years ago

I suspect this change is to blame:

+       /**
+        * Pause the currently playing song.
+        */
        private synchronized void pause() {
-               if (mp.isPlaying()) {
+               // Sometimes the call to isPlaying can throw an error "internal/external state mismatch corrected"
+               // When this happens, I think the player moves itself to "paused" even though it's still playing.
+               //if (mp.isPlaying()) {
+               //      mp.pause();
+               //} else {
+               //      Log.w(TAG, "Odd condition - pause was called but the media player reported that it is already paused");
+               try{
+                       // this is a hack, but it seems to be the most consistent way to address the problem
+                       // this forces the media player to check its current state before trying to pause.
+                       int position = mp.getCurrentPosition();
+                       mp.seekTo(position);
+                       mp.start();
                        mp.pause();
-               } else {
-                       // do nothing
+               } catch (Exception e){
+                       Log.w(TAG, "Caught exception while trying to pause ", e);
                }
+               //}
                updateNotification();
        }

I made this (admittedly awkward) change to address a problem with the MusicPlayer failing to pause sometimes. I'm guessing the call to 'start()' is causing your phone to start playing when a phone call is received.

smithdtyler commented 9 years ago

I just pushed an update that I think will address this problem. I haven't been able to replicate the behavior you saw on my phone, but I've improved the pause handling. Please let me know if version 3.2.13 fixes this issue.

rdelro commented 9 years ago

Can do!

gryzor2 commented 9 years ago

Hi,

I have installed 3.2.14 and the bug seems fixed to me. I have left prettygoodmusicplayer in pause for hours and it has not unpaused unexpectedly.

Thank you very much ! Cheers,

Vincent

smithdtyler commented 9 years ago

Yay! On Aug 29, 2015 2:45 PM, "gryzor2" notifications@github.com wrote:

Hi,

I have installed 3.2.14 and the bug seems fixed to me. I have left prettygoodmusicplayer in pause for hours and it has not unpaused unexpectedly.

Thank you very much ! Cheers,

Vincent

— Reply to this email directly or view it on GitHub https://github.com/smithdtyler/prettygoodmusicplayer/issues/94#issuecomment-136033163 .