зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1222907 - report media status to MediaCastingBar. r=mfinkle.
This commit is contained in:
Родитель
41d245fdac
Коммит
dc55f38e26
|
@ -86,14 +86,24 @@ class ChromeCast implements GeckoMediaPlayer {
|
|||
@Override
|
||||
public void onStatusUpdated() {
|
||||
MediaStatus mediaStatus = remoteMediaPlayer.getMediaStatus();
|
||||
boolean isPlaying = mediaStatus.getPlayerState() == MediaStatus.PLAYER_STATE_PLAYING;
|
||||
|
||||
switch (mediaStatus.getPlayerState()) {
|
||||
case MediaStatus.PLAYER_STATE_PLAYING:
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("MediaPlayer:Playing", null));
|
||||
break;
|
||||
case MediaStatus.PLAYER_STATE_PAUSED:
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("MediaPlayer:Paused", null));
|
||||
break;
|
||||
case MediaStatus.PLAYER_STATE_IDLE:
|
||||
// TODO: Do we want to shutdown when there are errors?
|
||||
if (mediaStatus.getPlayerState() == MediaStatus.PLAYER_STATE_IDLE &&
|
||||
mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
|
||||
|
||||
if (mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Casting:Stop", null));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO: Do we need to handle other status such as buffering / unknown?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,8 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
|||
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Casting:Started",
|
||||
"Casting:Paused",
|
||||
"Casting:Playing",
|
||||
"Casting:Stopped");
|
||||
}
|
||||
|
||||
|
@ -71,6 +73,8 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
|||
public void onDestroy() {
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Casting:Started",
|
||||
"Casting:Paused",
|
||||
"Casting:Playing",
|
||||
"Casting:Stopped");
|
||||
}
|
||||
|
||||
|
@ -111,6 +115,12 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
|||
}
|
||||
mMediaPlay.setVisibility(GONE);
|
||||
mMediaPause.setVisibility(VISIBLE);
|
||||
} else if (event.equals("Casting:Paused")) {
|
||||
mMediaPause.setVisibility(GONE);
|
||||
mMediaPlay.setVisibility(VISIBLE);
|
||||
} else if (event.equals("Casting:Playing")) {
|
||||
mMediaPlay.setVisibility(GONE);
|
||||
mMediaPause.setVisibility(VISIBLE);
|
||||
} else if (event.equals("Casting:Stopped")) {
|
||||
hide();
|
||||
}
|
||||
|
|
|
@ -745,8 +745,16 @@ var CastingApps = {
|
|||
}
|
||||
|
||||
let status = aRemoteMedia.status;
|
||||
if (status == "completed") {
|
||||
switch (status) {
|
||||
case "started":
|
||||
Messaging.sendRequest({ type: "Casting:Playing" });
|
||||
break;
|
||||
case "paused":
|
||||
Messaging.sendRequest({ type: "Casting:Paused" });
|
||||
break;
|
||||
case "completed":
|
||||
this.closeExternal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -83,6 +83,9 @@ function RemoteMedia(id, listener) {
|
|||
|
||||
RemoteMedia.prototype = {
|
||||
shutdown: function shutdown() {
|
||||
Services.obs.removeObserver(this, "MediaPlayer:Playing");
|
||||
Services.obs.removeObserver(this, "MediaPlayer:Paused");
|
||||
|
||||
this._send("MediaPlayer:End", {}, (result, err) => {
|
||||
this._status = "shutdown";
|
||||
if ("onRemoteMediaStop" in this._listener) {
|
||||
|
@ -123,6 +126,8 @@ RemoteMedia.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
Services.obs.addObserver(this, "MediaPlayer:Playing", false);
|
||||
Services.obs.addObserver(this, "MediaPlayer:Paused", false);
|
||||
this._status = "started";
|
||||
})
|
||||
},
|
||||
|
@ -131,6 +136,29 @@ RemoteMedia.prototype = {
|
|||
return this._status;
|
||||
},
|
||||
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "MediaPlayer:Playing":
|
||||
if (this._status !== "started") {
|
||||
this._status = "started";
|
||||
if ("onRemoteMediaStatus" in this._listener) {
|
||||
this._listener.onRemoteMediaStatus(this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "MediaPlayer:Paused":
|
||||
if (this._status !== "paused") {
|
||||
this._status = "paused";
|
||||
if ("onRemoteMediaStatus" in this._listener) {
|
||||
this._listener.onRemoteMediaStatus(this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
_send: function(msg, data, callback) {
|
||||
data.id = this._id;
|
||||
send(msg, data, callback);
|
||||
|
|
Загрузка…
Ссылка в новой задаче