@Override
  public void playMedia(
      final MediaInfo mediaInfo,
      final boolean shouldLoop,
      final MediaPlayer.LaunchListener listener) {
    int requestIdNumber = getNextId();
    final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
    JSONObject message = null;
    ImageInfo iconImage = null;
    List<ImageInfo> images = mediaInfo.getImages();

    if (images != null && !images.isEmpty()) {
      iconImage = images.get(0);
    }

    final String iconSrc = iconImage == null ? null : iconImage.getUrl();
    final SubtitleInfo subtitleInfo = mediaInfo.getSubtitleInfo();

    try {
      message = createPlayMediaJsonRequest(mediaInfo, shouldLoop, requestId, iconSrc, subtitleInfo);
    } catch (JSONException e) {
      Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
      return;
    }

    ResponseListener<Object> response =
        new ResponseListener<Object>() {

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

          @Override
          public void onSuccess(Object object) {
            Util.postSuccess(
                listener,
                new MediaLaunchObject(launchSession, getMediaControl(), getPlaylistControl()));
          }
        };

    ServiceCommand<ResponseListener<Object>> command =
        new ServiceCommand<ResponseListener<Object>>(null, null, null, response);

    mActiveCommands.put(requestId, command);

    sendMessage(
        message,
        new ResponseListener<Object>() {

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

          @Override
          public void onSuccess(Object object) {}
        });
  }
  @Override
  public void displayImage(MediaInfo mediaInfo, MediaPlayer.LaunchListener listener) {
    String mediaUrl = null;
    String mimeType = null;
    String title = null;
    String desc = null;
    String iconSrc = null;

    if (mediaInfo != null) {
      mediaUrl = mediaInfo.getUrl();
      mimeType = mediaInfo.getMimeType();
      title = mediaInfo.getTitle();
      desc = mediaInfo.getDescription();

      if (mediaInfo.getImages() != null && mediaInfo.getImages().size() > 0) {
        ImageInfo imageInfo = mediaInfo.getImages().get(0);
        iconSrc = imageInfo.getUrl();
      }
    }

    displayImage(mediaUrl, mimeType, title, desc, iconSrc, listener);
  }