Make the media notification receiver more robust.

Sometimes the media notification does not contain the expected components, hence the code covered by the try/catch has been adjusted. This was reported in #533 for VLC.
In the future the whole media handling will probably be refactored.
This commit is contained in:
Daniele Gobbetti 2017-02-05 15:13:26 +01:00
parent cc917e97a6
commit b894c01822
1 changed files with 42 additions and 42 deletions

View File

@ -355,9 +355,6 @@ public class NotificationListener extends NotificationListenerService {
MediaController c;
try {
c = new MediaController(getApplicationContext(), (MediaSession.Token) extras.get(Notification.EXTRA_MEDIA_SESSION));
} catch (NullPointerException e) {
return false;
}
PlaybackState s = c.getPlaybackState();
stateSpec.position = (int) (s.getPosition() / 1000);
@ -400,6 +397,9 @@ public class NotificationListener extends NotificationListenerService {
GBApplication.deviceService().onSetMusicState(stateSpec);
return true;
} catch (NullPointerException e) {
return false;
}
}
@Override