Example #1
0
  @Override
  public boolean onError(MediaPlayer m, int what, int extra) {

    // The ResizableVideoView onMeasure method attempts to use the MediaPlayer
    // to measure
    // the VideoPlayer; but in the event of an error, the MediaPlayer
    // may report dimensions of zero video width and height.
    // Since VideoPlayer currently (7/10/2012) sets its size always
    // to some non-zero number, the MediaPlayer is invalidated here
    // to prevent onMeasure from setting width and height as zero.
    videoView.invalidateMediaPlayer(true);

    delayedStart = false;
    mediaReady = false;

    Log.e(
        "VideoPlayer",
        "onError: what is "
            + what
            + " 0x"
            + Integer.toHexString(what)
            + ", extra is "
            + extra
            + " 0x"
            + Integer.toHexString(extra));
    container
        .$form()
        .dispatchErrorOccurredEvent(
            this, "Source", ErrorMessages.ERROR_UNABLE_TO_LOAD_MEDIA, sourcePath);
    return true;
  }
Example #2
0
  /**
   * Sets the video source.
   *
   * <p>See {@link MediaUtil#determineMediaSource} for information about what a path can be.
   *
   * @param path the path to the video source
   */
  @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET, defaultValue = "")
  @SimpleProperty(
      description =
          "The \"path\" to the video.  Usually, this will be the "
              + "name of the video file, which should be added in the Designer.",
      category = PropertyCategory.BEHAVIOR)
  public void Source(String path) {
    if (inFullScreen) {
      container
          .$form()
          .fullScreenVideoAction(FullScreenVideoUtil.FULLSCREEN_VIDEO_ACTION_SOURCE, this, path);
    } else {
      sourcePath = (path == null) ? "" : path;

      // The source may change for the MediaPlayer, and
      // getVideoWidth or getVideoHeight may be called
      // creating an error in ResizableVideoView.
      videoView.invalidateMediaPlayer(true);

      // Clear the previous video.
      if (videoView.isPlaying()) {
        videoView.stopPlayback();
      }
      videoView.setVideoURI(null);
      videoView.clearAnimation();

      if (sourcePath.length() > 0) {
        Log.i("VideoPlayer", "Source path is " + sourcePath);

        try {
          mediaReady = false;
          MediaUtil.loadVideoView(videoView, container.$form(), sourcePath);
        } catch (IOException e) {
          container
              .$form()
              .dispatchErrorOccurredEvent(
                  this, "Source", ErrorMessages.ERROR_UNABLE_TO_LOAD_MEDIA, sourcePath);
          return;
        }

        Log.i("VideoPlayer", "loading video succeeded");
      }
    }
  }