Java Code Examples for android.media.MediaPlayer#getVideoWidth()

The following examples show how to use android.media.MediaPlayer#getVideoWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoView.java    From Android-VideoView with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPrepared(final MediaPlayer mp) {
	mCurrentState = STATE_PREPARED;

	if (mOnPreparedListener != null) {
		mOnPreparedListener.onPrepared(mMediaPlayer);
	}
	if (mMediaController != null) {
		mMediaController.setEnabled(true);
	}

	mVideoWidth = mp.getVideoWidth();
	mVideoHeight = mp.getVideoHeight();

	int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be
											// changed after seekTo()
											// call
	if (seekToPosition != 0) {
		seekTo(seekToPosition);
	}

	requestLayout();
	invalidate();
	if ((mVideoWidth != 0) && (mVideoHeight != 0)) {
		if (mTargetState == STATE_PLAYING) {
			mMediaPlayer.start();
			if (null != mMediaControllListener) {
				mMediaControllListener.onStart();
			}
		}
	} else {
		if (mTargetState == STATE_PLAYING) {
			mMediaPlayer.start();
			if (null != mMediaControllListener) {
				mMediaControllListener.onStart();
			}
		}
	}
}
 
Example 2
Source File: JCMediaManager.java    From JieCaoVideoPlayer-develop with MIT License 5 votes vote down vote up
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    currentVideoWidth = mp.getVideoWidth();
    currentVideoHeight = mp.getVideoHeight();
    mainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onVideoSizeChanged();
            }
        }
    });
}
 
Example 3
Source File: FragmentShowImage.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * get real width and height video
 */
private void getRealSize(MediaPlayer mp, TextureView mTextureView) {

    if (mp == null || mTextureView == null) {
        return;
    }

    //Get the dimensions of the video
    int videoWidth = mp.getVideoWidth();
    int videoHeight = mp.getVideoHeight();

    Display display = G.fragmentActivity.getWindowManager().getDefaultDisplay();

    int finalWith, finalHeight;

    finalWith = display.getWidth();
    finalHeight = (int) (((float) videoHeight / (float) videoWidth) * (float) display.getWidth());

    if (finalHeight > display.getHeight()) {
        finalWith = (int) (((float) finalWith / (float) finalHeight) * (float) display.getHeight());
        finalHeight = display.getHeight();
    }

    ViewGroup.LayoutParams lp = mTextureView.getLayoutParams();
    lp.width = finalWith;
    lp.height = finalHeight;
    mTextureView.setLayoutParams(lp);
}
 
Example 4
Source File: SysMediaPlayer.java    From PlayerBase with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    mVideoWidth = mp.getVideoWidth();
    mVideoHeight = mp.getVideoHeight();
    Bundle bundle = BundlePool.obtain();
    bundle.putInt(EventKey.INT_ARG1, mVideoWidth);
    bundle.putInt(EventKey.INT_ARG2, mVideoHeight);
    submitPlayerEvent(OnPlayerEventListener.PLAYER_EVENT_ON_VIDEO_SIZE_CHANGE,bundle);
}
 
Example 5
Source File: CommonUtil.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public static ViewSize getFitSize(Context context, MediaPlayer mediaPlayer) {
    int videoWidth = mediaPlayer.getVideoWidth();
    int videoHeight = mediaPlayer.getVideoHeight();
    double fit1 = videoWidth * 1.0 / videoHeight;

    int width2 = getScreenWidth(context);
    int height2 = getScreenHeight(context);
    double fit2 = width2 * 1.0 / height2;

    Log.e(TAG, "videoWidth = " + videoWidth + ", videoHeight = " + videoHeight + ",fit1 = "
            + fit1);
    Log.e(TAG, "width2 = " + width2 + ", height2 = " + height2 + ",fit2 = " + fit2);

    double fit = 1;
    if (fit1 > fit2) {
        fit = width2 * 1.0 / videoWidth;
    } else {
        fit = height2 * 1.0 / videoHeight;
    }

    Log.d(TAG, "fit = " + fit);

    ViewSize viewSize = new ViewSize();
    viewSize.width = (int) (fit * videoWidth);
    viewSize.height = (int) (fit * videoHeight);

    return viewSize;
}
 
Example 6
Source File: GPlayer.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp) {
    Log.v(LOGTAG, "onPrepared Called");
    videoWidth = mp.getVideoWidth();
    videoHeight = mp.getVideoHeight();
    if (videoWidth > currentDisplay.getWidth() || videoHeight > currentDisplay.getHeight()) {
        float heightRatio = (float) videoHeight / (float) currentDisplay.getHeight();
        float widthRatio = (float) videoWidth / (float) currentDisplay.getWidth();
        if (heightRatio > 1 || widthRatio > 1) {
            if (heightRatio > widthRatio) {
                videoHeight = (int) FloatMath.ceil((float) videoHeight / (float) heightRatio);
                videoWidth = (int) FloatMath.ceil((float) videoWidth / (float) heightRatio);
            } else {
                videoHeight = (int) FloatMath.ceil((float) videoHeight / (float) widthRatio);
                videoWidth = (int) FloatMath.ceil((float) videoWidth / (float) widthRatio);
            }
        }
    }
    // surfaceView.setLayoutParams(new FrameLayout.LayoutParams(videoWidth,
    // videoHeight));
    mp.start();
    if (null != mMediaListener) {
        mMediaListener.start();
    }

    // mediaController.setMediaPlayer(this);
    // mediaController.setAnchorView(this.findViewById(R.id.gplayer_surfaceview));
    // mediaController.setEnabled(true);
    // mediaController.show(5000);
    mHandler.sendEmptyMessage(MEDIA_PLAYER_PREPARED);

    mHandler.sendEmptyMessage(MEDIA_PLAYER_PROGRESS_UPDATE);
    mHandler.sendEmptyMessageDelayed(MEDIA_PLAYER_HIDDEN_CONTROL, 10000);
}
 
Example 7
Source File: VideoViewH264m3u8_4D.java    From letv with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    LogTag.i("onVideoSizeChanged(), width=" + width + ", heigth=" + height);
    VideoViewH264m3u8_4D.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8_4D.this.mVideoHeight = mp.getVideoHeight();
    if (!(VideoViewH264m3u8_4D.this.mVideoWidth == 0 || VideoViewH264m3u8_4D.this.mVideoHeight == 0)) {
        VideoViewH264m3u8_4D.this.getHolder().setFixedSize(VideoViewH264m3u8_4D.this.mVideoWidth, VideoViewH264m3u8_4D.this.mVideoHeight);
    }
    if (VideoViewH264m3u8_4D.this.mOnVideoSizeChangedListener != null) {
        VideoViewH264m3u8_4D.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8_4D.this.mVideoWidth, VideoViewH264m3u8_4D.this.mVideoHeight);
    }
}
 
Example 8
Source File: VideoViewH264m3u8HwLeMobile.java    From letv with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    VideoViewH264m3u8HwLeMobile.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8HwLeMobile.this.mVideoHeight = mp.getVideoHeight();
    if (!(VideoViewH264m3u8HwLeMobile.this.mVideoWidth == 0 || VideoViewH264m3u8HwLeMobile.this.mVideoHeight == 0)) {
        VideoViewH264m3u8HwLeMobile.this.getHolder().setFixedSize(VideoViewH264m3u8HwLeMobile.this.mVideoWidth, VideoViewH264m3u8HwLeMobile.this.mVideoHeight);
    }
    if (VideoViewH264m3u8HwLeMobile.this.mOnVideoSizeChangedListener != null) {
        VideoViewH264m3u8HwLeMobile.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8HwLeMobile.this.mVideoWidth, VideoViewH264m3u8HwLeMobile.this.mVideoHeight);
    }
}
 
Example 9
Source File: UniversalVideoView.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    mVideoWidth = mp.getVideoWidth();
    mVideoHeight = mp.getVideoHeight();
    Log.d(TAG, String.format("onVideoSizeChanged width=%d,height=%d", mVideoWidth, mVideoHeight));
    if (mVideoWidth != 0 && mVideoHeight != 0) {
        getHolder().setFixedSize(mVideoWidth, mVideoHeight);
        requestLayout();
    }
}
 
Example 10
Source File: VideoViewH264m3u8Hw.java    From letv with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    VideoViewH264m3u8Hw.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8Hw.this.mVideoHeight = mp.getVideoHeight();
    if (!(VideoViewH264m3u8Hw.this.mVideoWidth == 0 || VideoViewH264m3u8Hw.this.mVideoHeight == 0)) {
        VideoViewH264m3u8Hw.this.getHolder().setFixedSize(VideoViewH264m3u8Hw.this.mVideoWidth, VideoViewH264m3u8Hw.this.mVideoHeight);
    }
    if (VideoViewH264m3u8Hw.this.mOnVideoSizeChangedListener != null) {
        VideoViewH264m3u8Hw.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8Hw.this.mVideoWidth, VideoViewH264m3u8Hw.this.mVideoHeight);
    }
}
 
Example 11
Source File: VideoViewH264m3u8.java    From letv with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    LogTag.i("onVideoSizeChanged(), width=" + width + ", heigth=" + height);
    VideoViewH264m3u8.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8.this.mVideoHeight = mp.getVideoHeight();
    if (!(VideoViewH264m3u8.this.mVideoWidth == 0 || VideoViewH264m3u8.this.mVideoHeight == 0)) {
        VideoViewH264m3u8.this.mFisrtSetFixedSize = 1;
        VideoViewH264m3u8.this.getHolder().setFixedSize(VideoViewH264m3u8.this.mVideoWidth, VideoViewH264m3u8.this.mVideoHeight);
        LogTag.i("onVideoSizeChanged()->setFixedSize(), mVideoWidth=" + VideoViewH264m3u8.this.mVideoWidth + ", mVideoHeight=" + VideoViewH264m3u8.this.mVideoHeight);
    }
    if (VideoViewH264m3u8.this.mOnVideoSizeChangedListener != null) {
        VideoViewH264m3u8.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8.this.mVideoWidth, VideoViewH264m3u8.this.mVideoHeight);
        LogTag.i("onVideoSizeChanged()-> run user listener, mVideoWidth=" + VideoViewH264m3u8.this.mVideoWidth + ", mVideoHeight=" + VideoViewH264m3u8.this.mVideoHeight);
    }
}
 
Example 12
Source File: AndroidMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    int videoWidth = mp.getVideoWidth();
    int videoHeight = mp.getVideoHeight();
    if (videoWidth != 0 && videoHeight != 0) {
        mPlayerEventListener.onVideoSizeChanged(videoWidth, videoHeight);
    }
}
 
Example 13
Source File: JCMediaManager.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    currentVideoWidth = mp.getVideoWidth();
    currentVideoHeight = mp.getVideoHeight();
    mainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onVideoSizeChanged();
            }
        }
    });
}
 
Example 14
Source File: VideoView.java    From Android-VideoView with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onVideoSizeChanged(final MediaPlayer mp, final int width, final int height) {
	mVideoWidth = mp.getVideoWidth();
	mVideoHeight = mp.getVideoHeight();
	if (mVideoWidth != 0 && mVideoHeight != 0) {
		requestLayout();
	}
}
 
Example 15
Source File: SystemImplMediaPlayer.java    From android-jungle-mediaplayer with Apache License 2.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer player, int width, int height) {
    mVideoWidth = player.getVideoWidth();
    mVideoHeight = player.getVideoHeight();

    updateMediaRenderSize();

    mVideoSizeInitialized = true;
    trySeekToStartPosition();
}
 
Example 16
Source File: VideoViewH264m3u8Hw.java    From letv with Apache License 2.0 4 votes vote down vote up
public void onPrepared(MediaPlayer mp) {
    LogTag.i("onPrepared()");
    String currentDate = Tools.getCurrentDate();
    if (VideoViewH264m3u8Hw.this.mOnMediaStateTimeListener != null) {
        VideoViewH264m3u8Hw.this.mOnMediaStateTimeListener.onMediaStateTime(MeidaStateType.PREPARED, currentDate);
    }
    VideoViewH264m3u8Hw.this.mCurrentState = 2;
    VideoViewH264m3u8Hw.this.StateChange(VideoViewH264m3u8Hw.this.mCurrentState);
    VideoViewH264m3u8Hw videoViewH264m3u8Hw = VideoViewH264m3u8Hw.this;
    VideoViewH264m3u8Hw videoViewH264m3u8Hw2 = VideoViewH264m3u8Hw.this;
    VideoViewH264m3u8Hw.this.mCanSeekForward = true;
    videoViewH264m3u8Hw2.mCanSeekBack = true;
    videoViewH264m3u8Hw.mCanPause = true;
    if (VideoViewH264m3u8Hw.this.mOnPreparedListener != null) {
        VideoViewH264m3u8Hw.this.mOnPreparedListener.onPrepared(VideoViewH264m3u8Hw.this.mMediaPlayer);
    }
    VideoViewH264m3u8Hw.this.mLastUrl = ((FFMpegPlayer) mp).getLastUrl();
    VideoViewH264m3u8Hw.this.mVersion = ((FFMpegPlayer) mp).getVersion();
    if (VideoViewH264m3u8Hw.this.mMediaController != null) {
        VideoViewH264m3u8Hw.this.mMediaController.setEnabled(true);
    }
    int seekToPosition = VideoViewH264m3u8Hw.this.mSeekWhenPrepared;
    if (seekToPosition != 0) {
        VideoViewH264m3u8Hw.this.seekTo(seekToPosition);
    }
    VideoViewH264m3u8Hw.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8Hw.this.mVideoHeight = mp.getVideoHeight();
    if (VideoViewH264m3u8Hw.this.mVideoWidth == 0 || VideoViewH264m3u8Hw.this.mVideoHeight == 0) {
        if (VideoViewH264m3u8Hw.this.mTargetState == 3) {
            VideoViewH264m3u8Hw.this.start();
        }
    } else if (VideoViewH264m3u8Hw.this.mSurfaceWidth != VideoViewH264m3u8Hw.this.mVideoWidth || VideoViewH264m3u8Hw.this.mSurfaceHeight != VideoViewH264m3u8Hw.this.mVideoHeight) {
        VideoViewH264m3u8Hw.this.getHolder().setFixedSize(VideoViewH264m3u8Hw.this.mVideoWidth, VideoViewH264m3u8Hw.this.mVideoHeight);
    } else if (VideoViewH264m3u8Hw.this.mTargetState == 3) {
        VideoViewH264m3u8Hw.this.start();
        if (VideoViewH264m3u8Hw.this.mMediaController != null) {
            VideoViewH264m3u8Hw.this.mMediaController.show();
        }
    } else if (!VideoViewH264m3u8Hw.this.isPlaying()) {
        if ((seekToPosition != 0 || VideoViewH264m3u8Hw.this.getCurrentPosition() > 0) && VideoViewH264m3u8Hw.this.mMediaController != null) {
            VideoViewH264m3u8Hw.this.mMediaController.show(0);
        }
    }
}
 
Example 17
Source File: VideoViewH264m3u8_4D.java    From letv with Apache License 2.0 4 votes vote down vote up
public void onPrepared(MediaPlayer mp) {
    LogTag.i("onPrepared()");
    String currentDate = Tools.getCurrentDate();
    LetvMediaPlayerManager.getInstance().writePlayLog("系统当前时间:  " + currentDate + " VideoViewH264m3u8(软解m3u8)  onPrepared()");
    if (VideoViewH264m3u8_4D.this.mOnMediaStateTimeListener != null) {
        VideoViewH264m3u8_4D.this.mOnMediaStateTimeListener.onMediaStateTime(MeidaStateType.PREPARED, currentDate);
    }
    VideoViewH264m3u8_4D.this.mCurrentState = 2;
    VideoViewH264m3u8_4D.this.StateChange(VideoViewH264m3u8_4D.this.mCurrentState);
    VideoViewH264m3u8_4D videoViewH264m3u8_4D = VideoViewH264m3u8_4D.this;
    VideoViewH264m3u8_4D videoViewH264m3u8_4D2 = VideoViewH264m3u8_4D.this;
    VideoViewH264m3u8_4D.this.mCanSeekForward = true;
    videoViewH264m3u8_4D2.mCanSeekBack = true;
    videoViewH264m3u8_4D.mCanPause = true;
    if (VideoViewH264m3u8_4D.this.mOnPreparedListener != null) {
        VideoViewH264m3u8_4D.this.mOnPreparedListener.onPrepared(VideoViewH264m3u8_4D.this.mMediaPlayer);
    }
    VideoViewH264m3u8_4D.this.mLastUrl = ((FFMpegPlayer) mp).getLastUrl();
    VideoViewH264m3u8_4D.this.mVersion = ((FFMpegPlayer) mp).getVersion();
    LogTag.i(".so verison=" + VideoViewH264m3u8_4D.this.mVersion);
    if (VideoViewH264m3u8_4D.this.mMediaController != null) {
        VideoViewH264m3u8_4D.this.mMediaController.setEnabled(true);
    }
    int seekToPosition = VideoViewH264m3u8_4D.this.mSeekWhenPrepared;
    if (seekToPosition != 0) {
        VideoViewH264m3u8_4D.this.seekTo(seekToPosition);
    }
    VideoViewH264m3u8_4D.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8_4D.this.mVideoHeight = mp.getVideoHeight();
    if (VideoViewH264m3u8_4D.this.mVideoWidth == 0 || VideoViewH264m3u8_4D.this.mVideoHeight == 0) {
        if (VideoViewH264m3u8_4D.this.mTargetState == 3) {
            VideoViewH264m3u8_4D.this.start();
        }
    } else if (VideoViewH264m3u8_4D.this.mSurfaceWidth != VideoViewH264m3u8_4D.this.mVideoWidth || VideoViewH264m3u8_4D.this.mSurfaceHeight != VideoViewH264m3u8_4D.this.mVideoHeight) {
        VideoViewH264m3u8_4D.this.getHolder().setFixedSize(VideoViewH264m3u8_4D.this.mVideoWidth, VideoViewH264m3u8_4D.this.mVideoHeight);
    } else if (VideoViewH264m3u8_4D.this.mTargetState == 3) {
        VideoViewH264m3u8_4D.this.start();
        if (VideoViewH264m3u8_4D.this.mMediaController != null) {
            VideoViewH264m3u8_4D.this.mMediaController.show();
        }
    } else if (!VideoViewH264m3u8_4D.this.isPlaying() && ((seekToPosition != 0 || VideoViewH264m3u8_4D.this.getCurrentPosition() > 0) && VideoViewH264m3u8_4D.this.mMediaController != null)) {
        VideoViewH264m3u8_4D.this.mMediaController.show(0);
    }
    VideoViewH264m3u8_4D.this.palyer4dContrlHandle(seekToPosition);
}
 
Example 18
Source File: TextureVideoView.java    From texturevideoview with Apache License 2.0 4 votes vote down vote up
public void onPrepared(MediaPlayer mp) {
    mCurrentState = STATE_PREPARED;

    mCanPause = mCanSeekBack = mCanSeekForward = true;

    if (mOnPreparedListener != null) {
        mOnPreparedListener.onPrepared(mMediaPlayer);
    }
    if (mMediaController != null) {
        mMediaController.setEnabled(true);
    }
    mVideoWidth = mp.getVideoWidth();
    mVideoHeight = mp.getVideoHeight();

    int seekToPosition = mSeekWhenPrepared;  // mSeekWhenPrepared may be changed after seekTo() call
    if (seekToPosition != 0) {
        seekTo(seekToPosition);
    }
    if (mVideoWidth != 0 && mVideoHeight != 0) {
        //Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
        getSurfaceTexture().setDefaultBufferSize(mVideoWidth, mVideoHeight);
        // We won't get a "surface changed" callback if the surface is already the right size, so
        // start the video here instead of in the callback.
        if (mTargetState == STATE_PLAYING) {
            start();
            if (mMediaController != null) {
                mMediaController.show();
            }
        } else if (!isPlaying() &&
                (seekToPosition != 0 || getCurrentPosition() > 0)) {
            if (mMediaController != null) {
                // Show the media controls when we're paused into a video and make 'em stick.
                mMediaController.show(0);
            }
        }
    } else {
        // We don't know the video size yet, but should start anyway.
        // The video size might be reported to us later.
        if (mTargetState == STATE_PLAYING) {
            start();
        }
    }
}
 
Example 19
Source File: VideoViewH264m3u8Hw_4D.java    From letv with Apache License 2.0 4 votes vote down vote up
public void onPrepared(MediaPlayer mp) {
    LogTag.i("onPrepared()");
    String currentDate = Tools.getCurrentDate();
    LetvMediaPlayerManager.getInstance().writePlayLog("系统当前时间:  " + currentDate + " VideoViewH264m3u8Hw(硬解m3u8)  onPrepared()");
    if (VideoViewH264m3u8Hw_4D.this.mOnMediaStateTimeListener != null) {
        VideoViewH264m3u8Hw_4D.this.mOnMediaStateTimeListener.onMediaStateTime(MeidaStateType.PREPARED, currentDate);
    }
    VideoViewH264m3u8Hw_4D.this.mCurrentState = 2;
    VideoViewH264m3u8Hw_4D.this.StateChange(VideoViewH264m3u8Hw_4D.this.mCurrentState);
    VideoViewH264m3u8Hw_4D videoViewH264m3u8Hw_4D = VideoViewH264m3u8Hw_4D.this;
    VideoViewH264m3u8Hw_4D videoViewH264m3u8Hw_4D2 = VideoViewH264m3u8Hw_4D.this;
    VideoViewH264m3u8Hw_4D.this.mCanSeekForward = true;
    videoViewH264m3u8Hw_4D2.mCanSeekBack = true;
    videoViewH264m3u8Hw_4D.mCanPause = true;
    if (VideoViewH264m3u8Hw_4D.this.mOnPreparedListener != null) {
        VideoViewH264m3u8Hw_4D.this.mOnPreparedListener.onPrepared(VideoViewH264m3u8Hw_4D.this.mMediaPlayer);
    }
    VideoViewH264m3u8Hw_4D.this.mLastUrl = ((FFMpegPlayer) mp).getLastUrl();
    VideoViewH264m3u8Hw_4D.this.mVersion = ((FFMpegPlayer) mp).getVersion();
    if (VideoViewH264m3u8Hw_4D.this.mMediaController != null) {
        VideoViewH264m3u8Hw_4D.this.mMediaController.setEnabled(true);
    }
    int seekToPosition = VideoViewH264m3u8Hw_4D.this.mSeekWhenPrepared;
    if (seekToPosition != 0) {
        VideoViewH264m3u8Hw_4D.this.seekTo(seekToPosition);
    }
    VideoViewH264m3u8Hw_4D.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8Hw_4D.this.mVideoHeight = mp.getVideoHeight();
    if (VideoViewH264m3u8Hw_4D.this.mVideoWidth == 0 || VideoViewH264m3u8Hw_4D.this.mVideoHeight == 0) {
        if (VideoViewH264m3u8Hw_4D.this.mTargetState == 3) {
            VideoViewH264m3u8Hw_4D.this.start();
        }
    } else if (VideoViewH264m3u8Hw_4D.this.mSurfaceWidth != VideoViewH264m3u8Hw_4D.this.mVideoWidth || VideoViewH264m3u8Hw_4D.this.mSurfaceHeight != VideoViewH264m3u8Hw_4D.this.mVideoHeight) {
        VideoViewH264m3u8Hw_4D.this.getHolder().setFixedSize(VideoViewH264m3u8Hw_4D.this.mVideoWidth, VideoViewH264m3u8Hw_4D.this.mVideoHeight);
    } else if (VideoViewH264m3u8Hw_4D.this.mTargetState == 3) {
        VideoViewH264m3u8Hw_4D.this.start();
        if (VideoViewH264m3u8Hw_4D.this.mMediaController != null) {
            VideoViewH264m3u8Hw_4D.this.mMediaController.show();
        }
    } else if (!VideoViewH264m3u8Hw_4D.this.isPlaying() && ((seekToPosition != 0 || VideoViewH264m3u8Hw_4D.this.getCurrentPosition() > 0) && VideoViewH264m3u8Hw_4D.this.mMediaController != null)) {
        VideoViewH264m3u8Hw_4D.this.mMediaController.show(0);
    }
    VideoViewH264m3u8Hw_4D.this.palyer4dContrlHandle(seekToPosition);
}
 
Example 20
Source File: ReactVideoView.java    From react-native-video with MIT License 4 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp) {

    mMediaPlayerValid = true;
    mVideoDuration = mp.getDuration();

    WritableMap naturalSize = Arguments.createMap();
    naturalSize.putInt(EVENT_PROP_WIDTH, mp.getVideoWidth());
    naturalSize.putInt(EVENT_PROP_HEIGHT, mp.getVideoHeight());
    if (mp.getVideoWidth() > mp.getVideoHeight())
        naturalSize.putString(EVENT_PROP_ORIENTATION, "landscape");
    else
        naturalSize.putString(EVENT_PROP_ORIENTATION, "portrait");

    WritableMap event = Arguments.createMap();
    event.putDouble(EVENT_PROP_DURATION, mVideoDuration / 1000.0);
    event.putDouble(EVENT_PROP_CURRENT_TIME, mp.getCurrentPosition() / 1000.0);
    event.putMap(EVENT_PROP_NATURALSIZE, naturalSize);
    // TODO: Actually check if you can.
    event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
    event.putBoolean(EVENT_PROP_SLOW_FORWARD, true);
    event.putBoolean(EVENT_PROP_SLOW_REVERSE, true);
    event.putBoolean(EVENT_PROP_REVERSE, true);
    event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
    event.putBoolean(EVENT_PROP_STEP_BACKWARD, true);
    event.putBoolean(EVENT_PROP_STEP_FORWARD, true);
    mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD.toString(), event);

    applyModifiers();

    if (mUseNativeControls) {
        initializeMediaControllerIfNeeded();
        mediaController.setMediaPlayer(this);
        mediaController.setAnchorView(this);

        videoControlHandler.post(new Runnable() {
            @Override
            public void run() {
                mediaController.setEnabled(true);
                mediaController.show();
            }
        });
    }

    selectTimedMetadataTrack(mp);
}