Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java |
index 2dfc2dff9ade336ba265fd8543aa424140260cc7..5e09e0935e578ca7998430b66f2d811326d922db 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java |
@@ -60,7 +60,7 @@ public class CastNotificationControl implements MediaRouteController.UiListener, |
if (sInstance == null) { |
sInstance = new CastNotificationControl(context); |
} |
- sInstance.mMediaRouteController = mediaRouteController; |
+ sInstance.setRouteController(mediaRouteController); |
return sInstance; |
} |
} |
@@ -117,10 +117,15 @@ public class CastNotificationControl implements MediaRouteController.UiListener, |
} |
public void setRouteController(MediaRouteController controller) { |
+ if (mMediaRouteController != null) mMediaRouteController.removeUiListener(this); |
mMediaRouteController = controller; |
+ if (controller != null) controller.addUiListener(this); |
} |
private void updateNotification() { |
+ // Nothing shown yet, nothing to update. |
+ if (mNotificationBuilder == null) return; |
+ |
mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", "")); |
if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) { |
mNotificationBuilder.setPaused(mState != PlayerState.PLAYING); |
@@ -146,6 +151,8 @@ public class CastNotificationControl implements MediaRouteController.UiListener, |
// MediaRouteController.UiListener implementation. |
@Override |
public void onPlaybackStateChanged(PlayerState newState) { |
+ if (mState == newState) return; |
+ |
mState = newState; |
updateNotification(); |
} |
@@ -177,7 +184,9 @@ public class CastNotificationControl implements MediaRouteController.UiListener, |
@Override |
public void onTitleChanged(String title) { |
- mTitle = (title == null) ? "" : title; |
+ if (title == null || title.equals(mTitle)) return; |
+ |
+ mTitle = title; |
updateNotification(); |
} |