Bug 1055764 - "crash in java.lang.IllegalStateException: No current media session at com.google.android.gms.internal.gp.dV(Unknown Source)" [r=mark.finkle]
authorwesj <wjohnston@mozilla.com>
Thu, 02 Oct 2014 11:15:00 -0700
changeset 232615 ce37c5e7488253ad27bf05c377f3866f637188f0
parent 232614 d5ce88ef74a5d5aab53e3d47dfb719cb34e95dc8
child 232616 a259ef6f66d5bfbf088be05bdc5a7759fb21be34
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmark
bugs1055764
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055764 - "crash in java.lang.IllegalStateException: No current media session at com.google.android.gms.internal.gp.dV(Unknown Source)" [r=mark.finkle]
mobile/android/base/ChromeCast.java
--- a/mobile/android/base/ChromeCast.java
+++ b/mobile/android/base/ChromeCast.java
@@ -248,80 +248,95 @@ class ChromeCast implements GeckoMediaPl
         return true;
     }
 
     public void play(final EventCallback callback) {
         if (!verifySession(callback)) {
             return;
         }
 
-        remoteMediaPlayer.play(apiClient).setResultCallback(new ResultCallback<MediaChannelResult>() {
-            @Override
-            public void onResult(MediaChannelResult result) {
-                Status status = result.getStatus();
-                if (!status.isSuccess()) {
-                    debug("Unable to play: " + status.getStatusCode());
-                    callback.sendError(status.toString());
-                } else {
-                    callback.sendSuccess(null);
+        try {
+            remoteMediaPlayer.play(apiClient).setResultCallback(new ResultCallback<MediaChannelResult>() {
+                @Override
+                public void onResult(MediaChannelResult result) {
+                    Status status = result.getStatus();
+                    if (!status.isSuccess()) {
+                        debug("Unable to play: " + status.getStatusCode());
+                        callback.sendError(status.toString());
+                    } else {
+                        callback.sendSuccess(null);
+                    }
                 }
-            }
-        });
+            });
+        } catch(IllegalStateException ex) {
+            // The media player may throw if the session has been killed. For now, we're just catching this here.
+            callback.sendError("Error playing");
+        }
     }
 
     public void pause(final EventCallback callback) {
         if (!verifySession(callback)) {
             return;
         }
 
-        remoteMediaPlayer.pause(apiClient).setResultCallback(new ResultCallback<MediaChannelResult>() {
-            @Override
-            public void onResult(MediaChannelResult result) {
-                Status status = result.getStatus();
-                if (!status.isSuccess()) {
-                    debug("Unable to pause: " + status.getStatusCode());
-                    callback.sendError(status.toString());
-                } else {
-                    callback.sendSuccess(null);
+        try {
+            remoteMediaPlayer.pause(apiClient).setResultCallback(new ResultCallback<MediaChannelResult>() {
+                @Override
+                public void onResult(MediaChannelResult result) {
+                    Status status = result.getStatus();
+                    if (!status.isSuccess()) {
+                        debug("Unable to pause: " + status.getStatusCode());
+                        callback.sendError(status.toString());
+                    } else {
+                        callback.sendSuccess(null);
+                    }
                 }
-            }
-        });
+            });
+        } catch(IllegalStateException ex) {
+            // The media player may throw if the session has been killed. For now, we're just catching this here.
+            callback.sendError("Error pausing");
+        }
     }
 
     public void end(final EventCallback callback) {
         if (!verifySession(callback)) {
             return;
         }
 
-        Cast.CastApi.stopApplication(apiClient).setResultCallback(new ResultCallback<Status>() {
-            @Override
-            public void onResult(Status result) {
-                if (result.isSuccess()) {
-                    try {
-                        Cast.CastApi.removeMessageReceivedCallbacks(apiClient, remoteMediaPlayer.getNamespace());
-                        remoteMediaPlayer = null;
-                        mSessionId = null;
-                        apiClient.disconnect();
-                        apiClient = null;
+        try {
+            Cast.CastApi.stopApplication(apiClient).setResultCallback(new ResultCallback<Status>() {
+                @Override
+                public void onResult(Status result) {
+                    if (result.isSuccess()) {
+                        try {
+                            Cast.CastApi.removeMessageReceivedCallbacks(apiClient, remoteMediaPlayer.getNamespace());
+                            remoteMediaPlayer = null;
+                            mSessionId = null;
+                            apiClient.disconnect();
+                            apiClient = null;
 
-                        if (callback != null) {
-                            callback.sendSuccess(null);
-                        }
+                            if (callback != null) {
+                                callback.sendSuccess(null);
+                            }
 
-                        return;
-                    } catch(Exception ex) {
-                        debug("Error ending", ex);
+                            return;
+                        } catch(Exception ex) {
+                            debug("Error ending", ex);
+                        }
+                    }
+
+                    if (callback != null) {
+                        callback.sendError(result.getStatus().toString());
                     }
                 }
-
-                if (callback != null) {
-                    callback.sendError(result.getStatus().toString());
-                }
-            }
-        });
+            });
+        } catch(IllegalStateException ex) {
+            // The media player may throw if the session has been killed. For now, we're just catching this here.
+            callback.sendError("Error stopping");
+        }
     }
 
     class MirrorChannel implements MessageReceivedCallback {
         /**
          * @return custom namespace
          */
         public String getNamespace() {
             return "urn:x-cast:org.mozilla.mirror";