private void loadView(int id) {
    setContentView(id);
    getWindow().setBackgroundDrawable(null);
    mViewRoot = findViewById(R.id.video_root);
    mVideoView = (VideoView) findViewById(R.id.video);
    mVideoView.initialize(this, this, mIsHWCodec);
    mSubtitleContainer = findViewById(R.id.subtitle_container);
    mSubtitleText = (OutlineTextView) findViewById(R.id.subtitle_text);
    mSubtitleImage = (ImageView) findViewById(R.id.subtitle_image);
    mVideoLoadingText = (TextView) findViewById(R.id.video_loading_text);
    mVideoLoadingLayout = findViewById(R.id.video_loading);
    mLoadingProgressView = mVideoLoadingLayout.findViewById(R.id.video_loading_progress);
    player_back = (ImageButton) findViewById(R.id.player_back);
    player_back.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
          }
        });
    mLoadingAnimation = AnimationUtils.loadAnimation(VideoActivity.this, R.anim.loading_rotate);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  }
 private void setVideoLayout() {
   mVideoView.setVideoLayout(
       mVideoMode,
       VP.DEFAULT_ASPECT_RATIO,
       vPlayer.getVideoWidth(),
       vPlayer.getVideoHeight(),
       vPlayer.getVideoAspectRatio());
 }
 private void attachMediaController() {
   if (mMediaController != null) {
     mNeedLock = mMediaController.isLocked();
     mMediaController.release();
   }
   mMediaController = new MediaController(this, mNeedLock);
   mMediaController.setMediaPlayer(this);
   mMediaController.setAnchorView(mVideoView.getRootView());
   setFileName();
   setBatteryLevel();
 }
  @Override
  public float scale(float scaleFactor) {
    float userRatio = VP.DEFAULT_ASPECT_RATIO;
    int videoWidth = vPlayer.getVideoWidth();
    int videoHeight = vPlayer.getVideoHeight();
    float videoRatio = vPlayer.getVideoAspectRatio();
    float currentRatio = mVideoView.mVideoHeight / (float) videoHeight;

    currentRatio += (scaleFactor - 1);
    if (videoWidth * currentRatio >= VIDEO_MAXIMUM_WIDTH)
      currentRatio = VIDEO_MAXIMUM_WIDTH / (float) videoWidth;

    if (videoHeight * currentRatio >= VIDEO_MAXIMUM_HEIGHT)
      currentRatio = VIDEO_MAXIMUM_HEIGHT / (float) videoHeight;

    if (currentRatio < 0.5f) currentRatio = 0.5f;

    mVideoView.mVideoHeight = (int) (videoHeight * currentRatio);
    mVideoView.setVideoLayout(mVideoMode, userRatio, videoWidth, videoHeight, videoRatio);
    return currentRatio;
  }
 private void setupMedia() {
   myPlayer.setMediaController(myVideoController);
   myPlayer.setVideoURI(videoLocation);
 }
Example #6
0
 public final void onCompletion(MediaPlayer paramMediaPlayer) {
   if (VideoView.f(this.cZy) != null) VideoView.f(this.cZy).hide();
   if (VideoView.m(this.cZy) != null) VideoView.m(this.cZy).onCompletion(VideoView.e(this.cZy));
 }
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case OPEN_FILE:
              synchronized (mOpenLock) {
                if (!mOpened.get() && vPlayer != null) {
                  mOpened.set(true);
                  vPlayer.setVPlayerListener(vPlayerListener);
                  if (vPlayer.isInitialized()) mUri = vPlayer.getUri();

                  if (mVideoView != null) vPlayer.setDisplay(mVideoView.getHolder());
                  if (mUri != null)
                    vPlayer.initialize(
                        mUri,
                        mDisplayName,
                        mSaveUri,
                        getStartPosition(),
                        vPlayerListener,
                        mParentId,
                        mIsHWCodec);
                }
              }
              break;
            case OPEN_START:
              mVideoLoadingText.setText(R.string.video_layout_loading);
              setVideoLoadingLayoutVisibility(View.VISIBLE);
              break;
            case OPEN_SUCCESS:
              loadVPlayerPrefs();
              setVideoLoadingLayoutVisibility(View.GONE);
              setVideoLayout();
              vPlayer.start();
              attachMediaController();
              break;
            case OPEN_FAILED:
              resultFinish(RESULT_FAILED);
              break;
            case BUFFER_START:
              setVideoLoadingLayoutVisibility(View.VISIBLE);
              vPlayerHandler.sendEmptyMessageDelayed(BUFFER_PROGRESS, 1000);
              break;
            case BUFFER_PROGRESS:
              if (vPlayer.getBufferProgress() >= 100) {
                setVideoLoadingLayoutVisibility(View.GONE);
              } else {
                mVideoLoadingText.setText(
                    getString(
                        R.string.video_layout_buffering_progress, vPlayer.getBufferProgress()));
                vPlayerHandler.sendEmptyMessageDelayed(BUFFER_PROGRESS, 1000);
                stopPlayer();
              }
              break;
            case BUFFER_COMPLETE:
              setVideoLoadingLayoutVisibility(View.GONE);
              vPlayerHandler.removeMessages(BUFFER_PROGRESS);
              break;
            case CLOSE_START:
              mVideoLoadingText.setText(R.string.closing_file);
              setVideoLoadingLayoutVisibility(View.VISIBLE);
              break;
            case CLOSE_COMPLETE:
              mCloseComplete = true;
              break;
            case HW_FAILED:
              if (mVideoView != null) {
                mVideoView.setVisibility(View.GONE);
                mVideoView.setVisibility(View.VISIBLE);
                mVideoView.initialize(VideoActivity.this, VideoActivity.this, false);
              }
              break;
            case LOAD_PREFS:
              loadVPlayerPrefs();
              break;
          }
        }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_media);

    final DisplayMetrics dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    int swale = 0;
    if (swale == 0) {
      VideoHeight = (dm.widthPixels * 3) / 4;
    } else {
      VideoHeight = (dm.widthPixels * 9) / 16;
    }

    VideoView view = (VideoView) findViewById(R.id.video);
    view.setDisplayWidth(dm.widthPixels);
    view.setDisplayHeight(VideoHeight);
    view.setContext(this);
    view.setBackgroundColor(Color.BLACK);
    view.play();

    // String rtsp = "rtsp://10.4.0.95/video";
    // String rtsp = "rtsp://10.4.2.230/media/video1";
    final EditText rtspText = (EditText) findViewById(R.id.rtsptxt);

    final EditText rtspPort = (EditText) findViewById(R.id.rtspport);

    // 初始化参数
    String rtsp = rtspText.getText().toString();
    int port = Integer.parseInt(rtspPort.getText().toString());
    init(rtsp, port, 0, dm.widthPixels, VideoHeight);

    Button playButton = (Button) findViewById(R.id.playb);
    playButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            rtspPalyThread = new RtspPalyThread(MediaActivity.this);
            if (!isPlaying) {
              // 初始化参数
              String rtsp = rtspText.getText().toString();

              int port = Integer.parseInt(rtspPort.getText().toString());

              init(rtsp, port, 0, dm.widthPixels, VideoHeight);

              // 播放线程
              rtspPalyThread.start();
              isPlaying = true;
              Toast.makeText(MediaActivity.this, "视频播放开始...", Toast.LENGTH_LONG).show();
            } else {
              Toast.makeText(MediaActivity.this, "视频已经在播放...", Toast.LENGTH_LONG).show();
            }
          }
        });

    Button stopButton = (Button) findViewById(R.id.stopb);
    stopButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            if (isPlaying) {
              VideoFrames.frames.clear();
              stop();
              isPlaying = false;
              if (rtspPalyThread.isAlive()) {
                rtspPalyThread.interrupt();
                rtspPalyThread = null;
              }
              Toast.makeText(MediaActivity.this, "视频停止...", Toast.LENGTH_LONG).show();
            } else {
              Toast.makeText(MediaActivity.this, "视频未播放...", Toast.LENGTH_LONG).show();
            }
          }
        });

    Log.d(TAG, "MediaActivity Start Success!.....................................");
  }