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:
parent
cc917e97a6
commit
b894c01822
|
@ -355,9 +355,6 @@ public class NotificationListener extends NotificationListenerService {
|
||||||
MediaController c;
|
MediaController c;
|
||||||
try {
|
try {
|
||||||
c = new MediaController(getApplicationContext(), (MediaSession.Token) extras.get(Notification.EXTRA_MEDIA_SESSION));
|
c = new MediaController(getApplicationContext(), (MediaSession.Token) extras.get(Notification.EXTRA_MEDIA_SESSION));
|
||||||
} catch (NullPointerException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlaybackState s = c.getPlaybackState();
|
PlaybackState s = c.getPlaybackState();
|
||||||
stateSpec.position = (int) (s.getPosition() / 1000);
|
stateSpec.position = (int) (s.getPosition() / 1000);
|
||||||
|
@ -400,6 +397,9 @@ public class NotificationListener extends NotificationListenerService {
|
||||||
GBApplication.deviceService().onSetMusicState(stateSpec);
|
GBApplication.deviceService().onSetMusicState(stateSpec);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue