зеркало из 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
|
@Override
|
||||||
public void onStatusUpdated() {
|
public void onStatusUpdated() {
|
||||||
MediaStatus mediaStatus = remoteMediaPlayer.getMediaStatus();
|
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?
|
// TODO: Do we want to shutdown when there are errors?
|
||||||
if (mediaStatus.getPlayerState() == MediaStatus.PLAYER_STATE_IDLE &&
|
if (mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
|
||||||
mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
|
|
||||||
|
|
||||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Casting:Stop", null));
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Casting:Stop", null));
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// TODO: Do we need to handle other status such as buffering / unknown?
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
||||||
|
|
||||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||||
"Casting:Started",
|
"Casting:Started",
|
||||||
|
"Casting:Paused",
|
||||||
|
"Casting:Playing",
|
||||||
"Casting:Stopped");
|
"Casting:Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +73,8 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||||
"Casting:Started",
|
"Casting:Started",
|
||||||
|
"Casting:Paused",
|
||||||
|
"Casting:Playing",
|
||||||
"Casting:Stopped");
|
"Casting:Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +115,12 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
||||||
}
|
}
|
||||||
mMediaPlay.setVisibility(GONE);
|
mMediaPlay.setVisibility(GONE);
|
||||||
mMediaPause.setVisibility(VISIBLE);
|
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")) {
|
} else if (event.equals("Casting:Stopped")) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -745,8 +745,16 @@ var CastingApps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = aRemoteMedia.status;
|
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();
|
this.closeExternal();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,6 +83,9 @@ function RemoteMedia(id, listener) {
|
||||||
|
|
||||||
RemoteMedia.prototype = {
|
RemoteMedia.prototype = {
|
||||||
shutdown: function shutdown() {
|
shutdown: function shutdown() {
|
||||||
|
Services.obs.removeObserver(this, "MediaPlayer:Playing");
|
||||||
|
Services.obs.removeObserver(this, "MediaPlayer:Paused");
|
||||||
|
|
||||||
this._send("MediaPlayer:End", {}, (result, err) => {
|
this._send("MediaPlayer:End", {}, (result, err) => {
|
||||||
this._status = "shutdown";
|
this._status = "shutdown";
|
||||||
if ("onRemoteMediaStop" in this._listener) {
|
if ("onRemoteMediaStop" in this._listener) {
|
||||||
|
@ -123,6 +126,8 @@ RemoteMedia.prototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Services.obs.addObserver(this, "MediaPlayer:Playing", false);
|
||||||
|
Services.obs.addObserver(this, "MediaPlayer:Paused", false);
|
||||||
this._status = "started";
|
this._status = "started";
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -131,6 +136,29 @@ RemoteMedia.prototype = {
|
||||||
return this._status;
|
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) {
|
_send: function(msg, data, callback) {
|
||||||
data.id = this._id;
|
data.id = this._id;
|
||||||
send(msg, data, callback);
|
send(msg, data, callback);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче