Bug 1322114 - handle more media state change
When the playing media changes, there will be one more event
MEDIA_PLAYING_CHANGE, and the tab is still playing media.
This fix is to handle this situation then update Notification Bar.
MozReview-Commit-ID: DnsvaiLJ7Vw
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -106,19 +106,23 @@ public class MediaControlService extends
final Tab playingTab = mTabReference.get();
switch (msg) {
case MEDIA_PLAYING_CHANGE:
// The 'MEDIA_PLAYING_CHANGE' would only be received when the
// media starts or ends.
if (playingTab != tab && tab.isMediaPlaying()) {
mTabReference = new WeakReference<>(tab);
notifyControlInterfaceChanged(ACTION_PAUSE);
- } else if (playingTab == tab && !tab.isMediaPlaying()) {
- notifyControlInterfaceChanged(ACTION_STOP);
- mTabReference = new WeakReference<>(null);
+ } else if (playingTab == tab) {
+ // to understand what action happened in this event
+ String action = tab.isMediaPlaying() ? ACTION_RESUME : ACTION_STOP;
+ // if tab is not playing media, clear reference. Otherwise, keep it.
+ Tab tabInPlaying = tab.isMediaPlaying() ? tab : null;
+ notifyControlInterfaceChanged(action);
+ mTabReference = new WeakReference<>(tabInPlaying);
}
break;
case MEDIA_PLAYING_RESUME:
// user resume the paused-by-control media from page so that we
// should make the control interface consistent.
if (playingTab == tab && !isMediaPlaying()) {
notifyControlInterfaceChanged(ACTION_PAUSE);
}