@Override
  public ServiceSubscription<PlayStateListener> subscribePlayState(
      final PlayStateListener listener) {
    if (mPlayStateSubscription == null)
      mPlayStateSubscription =
          new URLServiceSubscription<MediaControl.PlayStateListener>(null, null, null, null);

    if (!connected) {
      connect(
          new ResponseListener<Object>() {

            @Override
            public void onError(ServiceCommandError error) {
              Util.postError(listener, error);
            }

            @Override
            public void onSuccess(Object response) {}
          });
    }

    if (!mPlayStateSubscription.getListeners().contains(listener))
      mPlayStateSubscription.addListener(listener);

    return mPlayStateSubscription;
  }
  public void handleMediaEvent(JSONObject payload) {
    String type = payload.optString("type");
    if (type.length() == 0) {
      String errorMsg = payload.optString("error");

      if (errorMsg.length() == 0) {
        return;
      } else {
        Log.w(Util.T, "Play State Error: " + errorMsg);
        if (mPlayStateSubscription != null) {
          for (PlayStateListener listener : mPlayStateSubscription.getListeners()) {
            Util.postError(listener, new ServiceCommandError(errorMsg));
          }
        }
      }
    }

    if (type.equals("playState")) {
      if (mPlayStateSubscription == null) return;

      String playStateString = payload.optString(type);
      if (playStateString.length() == 0) return;

      final MediaControl.PlayStateStatus playState = parsePlayState(playStateString);

      for (PlayStateListener listener : mPlayStateSubscription.getListeners()) {
        Util.postSuccess(listener, playState);
      }
    }
  }
  @Override
  public void close(ResponseListener<Object> listener) {
    mActiveCommands.clear();

    if (mPlayStateSubscription != null) {
      mPlayStateSubscription.unsubscribe();
      mPlayStateSubscription = null;
    }

    if (mMessageSubscription != null) {
      mMessageSubscription.unsubscribe();
      mMessageSubscription = null;
    }

    if (mWebAppPinnedSubscription != null) {
      mWebAppPinnedSubscription.unsubscribe();
      mWebAppPinnedSubscription = null;
    }

    service.getWebAppLauncher().closeWebApp(launchSession, listener);
  }