Bug 1311245 - part1 : don't need to dispatch event to gecko again when receving tab event 'MEDIA_PLAYING_CHANGE' and 'CLOSED'.
We don't need gecko to do something when receiving 'MEDIA_PLAYING_CHANGE' and 'CLOSED'. The only thing we need to do in Java side is to modify the media control's UI interface.
MozReview-Commit-ID: 6NrNraVOixg
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -97,26 +97,27 @@ public class MediaControlService extends
return;
}
final Tab playingTab = mTabReference.get();
switch (msg) {
case MEDIA_PLAYING_CHANGE:
if (playingTab != tab && tab.isMediaPlaying()) {
mTabReference = new WeakReference<>(tab);
- mController.getTransportControls().sendCustomAction(ACTION_START, null);
+ notifyControlInterfaceChanged(ACTION_PAUSE);
} else if (playingTab == tab && !tab.isMediaPlaying()) {
- mController.getTransportControls().stop();
+ notifyControlInterfaceChanged(ACTION_STOP);
+ mTabReference = new WeakReference<>(null);
}
break;
case CLOSED:
if (playingTab == null || playingTab == tab) {
// Remove the controls when the playing tab disappeared or was closed.
- mController.getTransportControls().stop();
+ notifyControlInterfaceChanged(ACTION_STOP);
}
break;
case FAVICON:
if (playingTab == tab) {
final String actionForPendingIntent = isMediaPlaying() ?
ACTION_PAUSE : ACTION_RESUME;
notifyControlInterfaceChanged(actionForPendingIntent);
}
@@ -168,17 +169,18 @@ public class MediaControlService extends
if (intent == null || intent.getAction() == null || !mInitialize) {
return;
}
Log.d(LOGTAG, "HandleIntent, action = " + intent.getAction() + ", actionState = " + mActionState);
switch (intent.getAction()) {
case ACTION_INIT :
// This action is used to create a service and do the initialization,
- // the actual operation would be executed via tab events.
+ // the actual operation would be executed via control interface's
+ // pending intent.
break;
case ACTION_START :
mController.getTransportControls().sendCustomAction(ACTION_START, null);
break;
case ACTION_RESUME :
mController.getTransportControls().play();
break;
case ACTION_PAUSE :