下面列出了android.media.MediaPlayer#getVideoHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth != 0 && mVideoHeight != 0) {
getSurfaceTexture().setDefaultBufferSize(mVideoWidth, mVideoHeight);
requestLayout();
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth != 0 && mVideoHeight != 0) {
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
requestLayout();
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if(mSizeChangeLinstener!=null){
mSizeChangeLinstener.doThings();
}
if (mVideoWidth != 0 && mVideoHeight != 0) {
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
}
}
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;
}
public void onVideoSizeChanged(MediaPlayer player, int width, int height) {
mVideoWidth = player.getVideoWidth();
mVideoHeight = player.getVideoHeight();
updateMediaRenderSize();
mVideoSizeInitialized = true;
trySeekToStartPosition();
}
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth != 0 && mVideoHeight != 0) {
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
}
}
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);
}
}
@Override
public void onVideoSizeChanged(MediaPlayer mediaPlayer, int i, int i1) {
currentVideoWidth = mediaPlayer.getVideoWidth();
currentVideoHeight = mediaPlayer.getVideoHeight();
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.listener() != null) {
JCVideoPlayerManager.listener().onVideoSizeChanged();
}
}
});
}
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);
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth != 0 && mVideoHeight != 0) {
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
requestLayout();
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
VideoViewH264m3u8Hw_4D.this.mVideoWidth = mp.getVideoWidth();
VideoViewH264m3u8Hw_4D.this.mVideoHeight = mp.getVideoHeight();
if (!(VideoViewH264m3u8Hw_4D.this.mVideoWidth == 0 || VideoViewH264m3u8Hw_4D.this.mVideoHeight == 0)) {
VideoViewH264m3u8Hw_4D.this.getHolder().setFixedSize(VideoViewH264m3u8Hw_4D.this.mVideoWidth, VideoViewH264m3u8Hw_4D.this.mVideoHeight);
}
if (VideoViewH264m3u8Hw_4D.this.mOnVideoSizeChangedListener != null) {
VideoViewH264m3u8Hw_4D.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8Hw_4D.this.mVideoWidth, VideoViewH264m3u8Hw_4D.this.mVideoHeight);
}
}
@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();
}
}
});
}
@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();
}
}
});
}
public void onPrepared(MediaPlayer mp) {
mCurrentState = STATE_PREPARED;
// Get the capabilities of the player for this stream
Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
MediaPlayer.BYPASS_METADATA_FILTER);
if (data != null) {
mCanPause = !data.has(Metadata.PAUSE_AVAILABLE)
|| data.getBoolean(Metadata.PAUSE_AVAILABLE);
mCanSeekBack = !data.has(Metadata.SEEK_BACKWARD_AVAILABLE)
|| data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE);
mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE)
|| data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE);
} else {
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);
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
// We didn't actually change the size (it was already at the size
// we need), so we won't get a "surface changed" callback, 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();
}
}
}
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);
}
}
}
public void onPrepared(MediaPlayer mp) {
// briefly show the mediacontroller
mIsPrepared = true;
if (mOnPreparedListener != null) {
mOnPreparedListener.onPrepared(mMediaPlayer);
}
if (mMediaController != null) {
mMediaController.setEnabled(true);
}
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
if (mVideoWidth != 0 && mVideoHeight != 0) {
//Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
// We didn't actually change the size (it was already at the size
// we need), so we won't get a "surface changed" callback, so
// start the video here instead of in the callback.
if (mSeekWhenPrepared != 0) {
mMediaPlayer.seekTo(mSeekWhenPrepared);
}
if (mStartWhenPrepared) {
mMediaPlayer.start();
if (mMediaController != null) {
mMediaController.show();
}
} else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) {
if (mMediaController != null) {
mMediaController.show(0); // show the media controls when we're paused into a video and make 'em stick.
}
}
}
} else {
Log.d("VideoView", "Couldn't get video size after prepare(): " +
mVideoWidth + "/" + mVideoHeight);
// The file was probably truncated or corrupt. Start anyway, so
// that we play whatever short snippet is there and then get
// the "playback completed" event.
if (mStartWhenPrepared) {
mMediaPlayer.start();
}
}
}
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);
}
public void onPrepared(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);
}
if (mVideoWidth != 0 && mVideoHeight != 0) {
//Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight);
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
// We didn't actually change the size (it was already at the size
// we need), so we won't get a "surface changed" callback, 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();
}
}
}
} 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();
}
}
}
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);
getHolder().setFixedSize(mVideoWidth, mVideoHeight);
if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
// We didn't actually change the size (it was already at the size
// we need), so we won't get a "surface changed" callback, 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();
}
}
}
@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);
}