示例#1
0
  @WXComponentProp(name = "playStatus")
  public void setPlaystatus(String playstatus) {

    if (mPrepared && !mError && !mStopped) {
      if (playstatus.equals("play")) {
        mVideoView.start();
      } else if (playstatus.equals("pause")) {
        mVideoView.pause();
      } else if (playstatus.equals("stop")) {
        mVideoView.stopPlayback();
        mStopped = true;
      }
    } else if ((mError || mStopped) && playstatus.equals("play")) {
      mError = false;
      mVideoView.resume();
      mProgressBar.setVisibility(View.VISIBLE);
    }
  }
示例#2
0
  @Override
  public void flushView() {
    super.flushView();

    if (!TextUtils.isEmpty(mSrc) && mSrcChanged) {
      mSrcChanged = false;
      mVideoView.setVideoURI(Uri.parse(mSrc));
      mProgressBar.setVisibility(View.VISIBLE);
    }
  }
示例#3
0
  @Override
  protected void initView() {
    FrameLayout videoRoot = new FrameLayout(mContext);
    videoRoot.setBackgroundColor(WXResourceUtils.getColor("#ee000000"));

    mVideoView = new WXVideoView(mContext);
    FrameLayout.LayoutParams videoLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    videoLayoutParams.gravity = Gravity.CENTER;
    mVideoView.setLayoutParams(videoLayoutParams);
    videoRoot.addView(mVideoView);

    mProgressBar = new ProgressBar(mContext);
    FrameLayout.LayoutParams pLayoutParams =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    mProgressBar.setLayoutParams(pLayoutParams);
    pLayoutParams.gravity = Gravity.CENTER;
    videoRoot.addView(mProgressBar);

    final MediaController controller = new MediaController(mContext);

    controller.setAnchorView(videoRoot);

    mVideoView.setOnErrorListener(
        new MediaPlayer.OnErrorListener() {

          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onError:" + what);
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = false;
            mError = true;

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FAIL)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FAIL);
            }
            return true;
          }
        });

    mVideoView.setOnPreparedListener(
        new MediaPlayer.OnPreparedListener() {

          @Override
          public void onPrepared(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPrepared");
            }
            mProgressBar.setVisibility(View.GONE);
            mPrepared = true;
            if (mAutoPlay) {
              mVideoView.start();
            }
            mVideoView.seekTo(5);
            if (!mStopped) {
              controller.show(3);
            } else {
              controller.hide();
            }
            mStopped = false;
          }
        });

    mVideoView.setOnCompletionListener(
        new MediaPlayer.OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onCompletion");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_FINISH)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_FINISH);
            }
          }
        });

    mVideoView.setOnVideoPauseListener(
        new WXVideoView.VideoPlayListener() {

          @Override
          public void onPause() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onPause");
            }
            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_PAUSE)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_PAUSE);
            }
          }

          @Override
          public void onStart() {
            if (WXEnvironment.isApkDebugable()) {
              WXLogUtils.d("Video", "onStart");
            }

            if (mDomObj.event != null && mDomObj.event.contains(WXEventType.VIDEO_START)) {
              WXSDKManager.getInstance().fireEvent(mInstanceId, getRef(), WXEventType.VIDEO_START);
            }
          }
        });

    mVideoView.setMediaController(controller);
    controller.setMediaPlayer(mVideoView);

    mHost = videoRoot;
  }