Bug 1222907 - report media status to MediaCastingBar. r=mfinkle.

This commit is contained in:
Shih-Chiang Chien 2015-11-09 17:56:59 +08:00
Родитель 41d245fdac
Коммит dc55f38e26
4 изменённых файлов: 64 добавлений и 8 удалений

Просмотреть файл

@ -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);