コード例 #1
0
ファイル: MediaPlayer.java プロジェクト: happyyang/vtk-2
  /**
   * Provided model data:
   *
   * <ul>
   *   <li><code>mediaResource</code> - if media reference points to a local resource, then the
   *       {@link Resource} will be provided under this key if it could be retrieved from the
   *       repository.
   *   <li><code>media</code> - a {@link URL} instance pointing to the media.
   *   <li>TODO complete me
   * </ul>
   *
   * @param model model to add data to
   * @param mediaRef the media resource URI as a string
   * @param height height of inserted video
   * @param width width of inserted video
   * @param autoplay whether to setup player to start automatically or not.
   * @param contentType
   * @param streamType
   * @param poster
   * @param showDL
   * @throws AuthorizationException
   */
  public void addMediaPlayer(
      Map<String, Object> model,
      String mediaRef,
      String height,
      String width,
      String autoplay,
      String contentType,
      String streamType,
      String poster,
      String showDL) {

    if (URL.isEncoded(mediaRef)) {
      mediaRef = urlDecodeMediaRef(mediaRef);
    }

    Resource mediaResource = null;
    try {
      mediaResource = getLocalResource(mediaRef);
    } catch (AuthorizationException e) {
      return; // not able to read local resource - abort
    } catch (AuthenticationException e) {
      return; // not able to read local resource - abort
    } catch (Exception e) {
      // ignore
    }

    if (mediaResource != null) {
      model.put("mediaResource", mediaResource);
    }

    if ((height != null && !"".equals(height)) && (width != null && !"".equals(width))) {
      model.put("height", height);
      model.put("width", width);
    }

    if (autoplay != null && !autoplay.isEmpty()) model.put("autoplay", autoplay);

    if (streamType != null && !streamType.isEmpty()) model.put("streamType", streamType);

    model.put("showDL", showDL != null && showDL.equalsIgnoreCase("true") ? "true" : "false");

    if (poster != null && !poster.isEmpty()) model.put("poster", poster);
    else addPosterUrl(mediaResource, model);

    if (contentType != null && !contentType.isEmpty()) {
      model.put("contentType", contentType);
    } else if (mediaResource != null) {
      model.put("contentType", mediaResource.getContentType());
    } else {
      model.put("contentType", MimeHelper.map(mediaRef));
    }
    model.put("extension", MimeHelper.findExtension(mediaRef));
    model.put("nanoTime", System.nanoTime());

    if (mediaResource != null) {
      addMediaUrl(mediaResource, model);
    } else {
      addMediaUrl(mediaRef, model);
    }
  }
コード例 #2
0
ファイル: MediaPlayer.java プロジェクト: happyyang/vtk-2
  /**
   * Provided model data:
   *
   * <ul>
   *   <li><code>mediaResource</code> - if media reference points to a local resource, then the
   *       {@link Resource} will be provided under this key if it could successfully be retrieved
   *       from the repository.
   *   <li><code>media</code> - a {@link URL} instance pointing to the media.
   *   <li>TODO complete me
   * </ul>
   *
   * @param model MVC model
   * @param mediaRef media reference/link as string
   */
  public void addMediaPlayer(Map<String, Object> model, String mediaRef) {

    if (URL.isEncoded(mediaRef)) {
      mediaRef = urlDecodeMediaRef(mediaRef);
    }

    Resource mediaResource = null;
    try {
      mediaResource = getLocalResource(mediaRef);
    } catch (AuthorizationException e) {
      return; // not able to read local resource - abort
    } catch (AuthenticationException e) {
      return; // not able to read local resource - abort
    } catch (Exception e) {
      // ignore
    }

    if (mediaResource != null) {
      model.put("mediaResource", mediaResource);
    }

    addPosterUrl(mediaResource, model);
    model.put("extension", MimeHelper.findExtension(mediaRef));

    if (mediaResource != null) {
      model.put("contentType", mediaResource.getContentType());
    } else {
      model.put("contentType", MimeHelper.map(mediaRef));
    }

    model.put("nanoTime", System.nanoTime());

    if (mediaResource != null) {
      addMediaUrl(mediaResource, model);
    } else {
      addMediaUrl(mediaRef, model);
    }
  }