зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1290467 - part3 : notify MediaControlService with event 'MEDIA_PLAYING_CHANGE'. r=sebastian
The 'MEDIA_PLAYING_CHANGE' is used for controling media control interface and the 'AUDIO_PLAYING_CHANGE' is used for showing the tab sound indicator. MozReview-Commit-ID: 8hZjC77Ju71 --HG-- extra : rebase_source : 3699ea482e89a5c2535defce8ca2689a180d5c49
This commit is contained in:
Родитель
9069f0f0d5
Коммит
8b77ea4d53
|
@ -84,6 +84,7 @@ public class Tab {
|
|||
private volatile int mLoadProgress;
|
||||
private volatile int mRecordingCount;
|
||||
private volatile boolean mIsAudioPlaying;
|
||||
private volatile boolean mIsMediaPlaying;
|
||||
private String mMostRecentHomePanel;
|
||||
private boolean mShouldShowToolbarWithoutAnimationOnFirstSelection;
|
||||
|
||||
|
@ -812,6 +813,26 @@ public class Tab {
|
|||
return mRecordingCount > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "MediaPlaying" is used for controling media control interface and
|
||||
* means the tab has playing media.
|
||||
*
|
||||
* @param isMediaPlaying the tab has any playing media or not
|
||||
*/
|
||||
public void setIsMediaPlaying(boolean isMediaPlaying) {
|
||||
mIsMediaPlaying = isMediaPlaying;
|
||||
}
|
||||
|
||||
public boolean isMediaPlaying() {
|
||||
return mIsMediaPlaying;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "AudioPlaying" is used for showing the tab sound indicator and means
|
||||
* the tab has playing media and the media is audible.
|
||||
*
|
||||
* @param isAudioPlaying the tab has any audible playing media or not
|
||||
*/
|
||||
public void setIsAudioPlaying(boolean isAudioPlaying) {
|
||||
mIsAudioPlaying = isAudioPlaying;
|
||||
}
|
||||
|
|
|
@ -123,7 +123,8 @@ public class Tabs implements GeckoEventListener {
|
|||
"Tab:ViewportMetadata",
|
||||
"Tab:StreamStart",
|
||||
"Tab:StreamStop",
|
||||
"Tab:AudioPlayingChange");
|
||||
"Tab:AudioPlayingChange",
|
||||
"Tab:MediaPlaybackChange");
|
||||
|
||||
mPrivateClearColor = Color.RED;
|
||||
|
||||
|
@ -573,6 +574,9 @@ public class Tabs implements GeckoEventListener {
|
|||
} else if (event.equals("Tab:AudioPlayingChange")) {
|
||||
tab.setIsAudioPlaying(message.getBoolean("isAudioPlaying"));
|
||||
notifyListeners(tab, TabEvents.AUDIO_PLAYING_CHANGE);
|
||||
} else if (event.equals("Tab:MediaPlaybackChange")) {
|
||||
tab.setIsMediaPlaying(message.getBoolean("active"));
|
||||
notifyListeners(tab, TabEvents.MEDIA_PLAYING_CHANGE);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -633,6 +637,7 @@ public class Tabs implements GeckoEventListener {
|
|||
BOOKMARK_REMOVED,
|
||||
AUDIO_PLAYING_CHANGE,
|
||||
OPENED_FROM_TABS_TRAY,
|
||||
MEDIA_PLAYING_CHANGE,
|
||||
}
|
||||
|
||||
public void notifyListeners(Tab tab, TabEvents msg) {
|
||||
|
|
|
@ -104,25 +104,21 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
|||
return;
|
||||
}
|
||||
|
||||
final Tab playingTab = mTabReference.get();
|
||||
switch (msg) {
|
||||
case AUDIO_PLAYING_CHANGE:
|
||||
if (tab == mTabReference.get()) {
|
||||
return;
|
||||
case MEDIA_PLAYING_CHANGE:
|
||||
if (playingTab != tab && tab.isMediaPlaying()) {
|
||||
mTabReference = new WeakReference<>(tab);
|
||||
mController.getTransportControls().sendCustomAction(ACTION_START, null);
|
||||
} else if (playingTab == tab && !tab.isMediaPlaying()) {
|
||||
mController.getTransportControls().stop();
|
||||
}
|
||||
|
||||
if (!tab.isAudioPlaying()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mTabReference = new WeakReference<>(tab);
|
||||
notifyControlInterfaceChanged(ACTION_PAUSE);
|
||||
break;
|
||||
|
||||
case CLOSED:
|
||||
final Tab playingTab = mTabReference.get();
|
||||
if (playingTab == null || playingTab == tab) {
|
||||
// The playing tab disappeared or was closed. Remove the controls and stop the service.
|
||||
notifyControlInterfaceChanged(ACTION_REMOVE_CONTROL);
|
||||
// Remove the controls when the playing tab disappeared or was closed.
|
||||
mController.getTransportControls().stop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -236,6 +232,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
|||
notifyControlInterfaceChanged(ACTION_STOP);
|
||||
notifyObservers("MediaControl", "mediaControlStopped");
|
||||
mActionState = ACTION_STOP;
|
||||
mTabReference = new WeakReference<>(null);
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3567,6 +3567,7 @@ Tab.prototype = {
|
|||
this.browser.addEventListener("VideoBindingCast", this, true, true);
|
||||
|
||||
Services.obs.addObserver(this, "before-first-paint", false);
|
||||
Services.obs.addObserver(this, "media-playback", false);
|
||||
|
||||
// Always intialise new tabs with basic session store data to avoid
|
||||
// problems with functions that always expect it to be present
|
||||
|
@ -3676,6 +3677,7 @@ Tab.prototype = {
|
|||
this.browser.removeEventListener("VideoBindingCast", this, true, true);
|
||||
|
||||
Services.obs.removeObserver(this, "before-first-paint");
|
||||
Services.obs.removeObserver(this, "media-playback", false);
|
||||
|
||||
// Make sure the previously selected panel remains selected. The selected panel of a deck is
|
||||
// not stable when panels are removed.
|
||||
|
@ -4453,6 +4455,21 @@ Tab.prototype = {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "media-playback":
|
||||
if (!aSubject) {
|
||||
return;
|
||||
}
|
||||
|
||||
let winId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
if (this.browser.outerWindowID == winId) {
|
||||
Messaging.sendRequest({
|
||||
type: "Tab:MediaPlaybackChange",
|
||||
tabID: this.id,
|
||||
active: aData === "active"
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче