Bug 1053889 - Handle null devices returned from Chromecast code. r=mfinkle
This commit is contained in:
@@ -24,6 +24,8 @@ import android.util.Log;
|
||||
import com.google.android.gms.cast.CastMediaControlIntent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* Wraper for different MediaRouter types supproted by Android. i.e. Chromecast, Miracast, etc. */
|
||||
interface GeckoMediaPlayer {
|
||||
@@ -61,7 +63,7 @@ class MediaPlayerManager implements NativeEventListener,
|
||||
|
||||
private final Context context;
|
||||
private final MediaRouter mediaRouter;
|
||||
private final HashMap<String, GeckoMediaPlayer> displays = new HashMap<String, GeckoMediaPlayer>();
|
||||
private final Map<String, GeckoMediaPlayer> displays = new HashMap<String, GeckoMediaPlayer>();
|
||||
private static MediaPlayerManager instance;
|
||||
|
||||
@JNITarget
|
||||
@@ -125,9 +127,17 @@ class MediaPlayerManager implements NativeEventListener,
|
||||
if ("MediaPlayer:Get".equals(event)) {
|
||||
final JSONObject result = new JSONObject();
|
||||
final JSONArray disps = new JSONArray();
|
||||
for (GeckoMediaPlayer disp : displays.values()) {
|
||||
|
||||
final Iterator<GeckoMediaPlayer> items = displays.values().iterator();
|
||||
while (items.hasNext()) {
|
||||
GeckoMediaPlayer disp = items.next();
|
||||
try {
|
||||
disps.put(disp.toJSON());
|
||||
JSONObject json = disp.toJSON();
|
||||
if (json == null) {
|
||||
items.remove();
|
||||
} else {
|
||||
disps.put(json);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
// This may happen if the device isn't a real Chromecast,
|
||||
// for example Firefly casting devices.
|
||||
|
||||
Reference in New Issue
Block a user