49

I am attempting to write a RemotePlaybackClient sample app, in part because the one published by Google crashes aapt.

I can get RemotePlaybackClient to support play(), and it plays back a video on a Chromecast.

However, when I call stop(), to stop playback of the video, while the Chromecast does stop playback (showing a black screen with a cast icon centered), the SessionActionCallback that I pass into the stop() call does not get called with onResult():

  private void stop() {
    logToTranscript(getActivity().getString(R.string.stop_requested));

    SessionActionCallback stopCB=new SessionActionCallback() {
      @Override
      public void onResult(Bundle data, String sessionId,
                           MediaSessionStatus sessionStatus) {
        logToTranscript(getActivity().getString(R.string.stopped));
        isPlaying=false;
        isPaused=false;
        getActivity().supportInvalidateOptionsMenu();
        endSession();
      }
    };

    client.stop(null, stopCB);
  }

The same thing happens if I try pause() -- the SessionActionCallback passed to pause() is not invoked.

The sample code published by Google shows that these callbacks should be invoked, but, again, I can't get that to compile successfully.

Does anyone know under what circumstances the SessionActionCallback would not work, while the ItemActionCallback used with play() would work?

UPDATE

I have filed issue 66996 and issue 67032, the latter of which is specifically the problem I am seeing here, as I run into this same problem with the official sample app.

Camo
  • 133
  • 2
  • 14
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I did get the sample to compile in Eclipse, and it too is not receiving anything on its `SessionActionCallback` when `stop()` or `pause()` is called. – CommonsWare Mar 11 '14 at 18:31
  • What receiver are you using? – Ali Naddaf Mar 12 '14 at 00:06
  • @AliNaddaf: I am using a Chromecast from a hardware standpoint. `RemotePlaybackClient` does not specify a receiver, near as I can tell, so presumably under the covers Chromecast is using the default receiver. – CommonsWare Mar 12 '14 at 10:50
  • The first time I call `stop`, from the sample app, a `MediaRouteProviderProtocol.SERVICE_MSG_GENERIC_FAILURE` occurs, but pressing it once more will call `SessionActionCallback.onResult` twice. So, it seems like `RegisteredMediaRouteProvider.sendControlRequest` isn't being called the first time around, for some reason. – adneal Mar 26 '14 at 17:17
  • @adneal: Where you are seeing `SERVICE_MSG_GENERIC_FAILURE`, since `stop()` is `void`? – CommonsWare Mar 26 '14 at 17:24
  • @CommonsWare I compiled the `MediaRouter` lib in Eclipse then logged the `Handler` that receives each `Message` in `RegisteredMediaRouteProvider`. – adneal Mar 26 '14 at 17:29
  • @adneal: Ah! OK, I'll do some more poking around on this, though probably not until April. Thanks! – CommonsWare Mar 26 '14 at 17:32
  • hopefully this may at the least indicate for you a work-around https://android.googlesource.com/platform/frameworks/support.git/+/android-4.4_r1.1%5E2%5E2..android-4.4_r1.1%5E2/ – Technivorous Mar 27 '14 at 16:40

1 Answers1

1

I beleive all Answer reside on how you make connection. Because in google code ,code says that client which you had made shold not leave session and should not be null.

if (!mClient.hasSession()) {
   // ignore if no session
   return;
}

/*********Rest of the code would be unreachable***********/

@Override
public void pause() {
    if (!mClient.hasSession()) {
        // ignore if no session
        return;
    }
    if (DEBUG) {
        Log.d(TAG, "pause");
    }
    mClient.pause(null, new SessionActionCallback() {
        @Override
        public void onResult(Bundle data, String sessionId, MediaSessionStatus sessionStatus) {
            logStatus("pause: succeeded", sessionId, sessionStatus, null, null);
            if (mCallback != null) {
                mCallback.onPlaylistChanged();
            }
        }
        @Override
        public void onError(String error, int code, Bundle data) {
            logError("pause: failed", error, code);
        }
    });
}
Maveňツ
  • 1
  • 12
  • 50
  • 89
DeepakPanwar
  • 1,389
  • 14
  • 22