@Override public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { mVideoHeight = mp.getVideoHeight(); mVideoWidth = mp.getVideoWidth(); if (mVideoHeight > 0 && mVideoWidth > 0) mVideoSurface.adjustSize( mContentView.getWidth(), mContentView.getHeight(), mMediaPlayer.getVideoWidth(), mMediaPlayer.getVideoHeight()); }
@Override public void onPrepared(MediaPlayer mp) { // 必须是正常状态 if (mCurrentState == STATE_PREPARING) { mCurrentState = STATE_PREPARED; try { mDuration = mp.getDuration(); } catch (IllegalStateException e) { Logger.e(e); } try { mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); } catch (IllegalStateException e) { Logger.e(e); } switch (mTargetState) { case STATE_PREPARED: if (mOnPreparedListener != null) mOnPreparedListener.onPrepared(mMediaPlayer); break; case STATE_PLAYING: start(); break; } } }
public void onPrepared(MediaPlayer mp) { mCurrentState = STATE_PREPARED; // modify by lxj // 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; // } 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 onVideoSizeChanged(MediaPlayer mp, int width, int height) { mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); if (mVideoWidth != 0 && mVideoHeight != 0) { getHolder().setFixedSize(mVideoWidth, mVideoHeight); } }
@Override public int getVideoWidth() { if (mMediaPlayer != null) { return mMediaPlayer.getVideoWidth(); } return 0; }
public void onVideoSizeChanged(MediaPlayer mediaPlayer, int width, int height) { try { mVideoWidth = mediaPlayer.getVideoWidth(); mVideoHeight = mediaPlayer.getVideoHeight(); } catch (IllegalStateException e) { Log.e(TAG, "MediaPlayer object has been released. Exception : " + e); return; } }
// A bunch event listeners for our VideoView // MediaPlayer.OnPreparedListener @Override public void onPrepared(MediaPlayer mp) { VideoPlayer.onPrepared(); Message msg = Message.obtain(mWebCoreHandler, PREPARED); Map<String, Object> map = new HashMap<String, Object>(); map.put("dur", new Integer(mp.getDuration())); map.put("width", new Integer(mp.getVideoWidth())); map.put("height", new Integer(mp.getVideoHeight())); msg.obj = map; mWebCoreHandler.sendMessage(msg); }
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); if (mMyChangeLinstener != null) { mMyChangeLinstener.doMyThings(); } if (mVideoWidth != 0 && mVideoHeight != 0) { getHolder().setFixedSize(mVideoWidth, mVideoHeight); } }
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); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (mSeekWhenPrepared != 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 (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; } } }
/** * Get the Image specific attributes * * @param filePath path to the file * @param obj represents the Media File Data * @param video if true get video attributes as well * @return a JSONObject that represents the Media File Data * @throws JSONException */ private JSONObject getAudioVideoData(String filePath, JSONObject obj, boolean video) throws JSONException { MediaPlayer player = new MediaPlayer(); try { player.setDataSource(filePath); player.prepare(); obj.put("duration", player.getDuration() / 1000); if (video) { obj.put("height", player.getVideoHeight()); obj.put("width", player.getVideoWidth()); } } catch (IOException e) { Log.d(LOG_TAG, "Error: loading video file"); } return obj; }
/** * Get the Image specific attributes * * @param filePath path to the file * @param obj represents the Media File Data * @param video if true get video attributes as well * @return a JSONObject that represents the Media File Data * @throws JSONException */ private JSONObject getAudioVideoMetadata(String filePath, JSONObject obj, boolean video) throws JSONException { MediaPlayer player = new MediaPlayer(); try { player.setDataSource(filePath); player.prepare(); obj.put(DURATION_FIELD, player.getDuration()); if (video) { obj.put(HEIGHT_FIELD, player.getVideoHeight()); obj.put(WIDTH_FIELD, player.getVideoWidth()); } } catch (IOException e) { Log.d(LOG_TAG, "Error: loading video file"); } return obj; }
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(); } } }
/** Returns the width of the video frame */ public int getVideoWidth() { if (!isPlayableOnTexture()) { // DebugLog.LOGD("Cannot get the video width if it is not playable on texture"); return -1; } if ((mCurrentState == MEDIA_STATE.NOT_READY) || (mCurrentState == MEDIA_STATE.ERROR)) { // DebugLog.LOGD("Cannot get the video width if it is not ready"); return -1; } int result = -1; mMediaPlayerLock.lock(); if (mMediaPlayer != null) result = mMediaPlayer.getVideoWidth(); mMediaPlayerLock.unlock(); return result; }
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(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(); } } }
/* 以原本视频分辨率的比例来调整预览播放窗口大小 */ private void setVideoRatio(String path) { int vh = 0; int vw = 0; if (player != null) { vh = player.getVideoHeight(); vw = player.getVideoWidth(); } if (vw == 0 || vh == 0) { return; } int width = mThumb.getWidth(); int height = (vh * width) / vw; if (height > mThumb.getHeight()) { height = mThumb.getHeight(); } ViewGroup.LayoutParams params = mVideo.getLayoutParams(); params.width = width; params.height = height; mVideo.setLayoutParams(params); }
public void onPrepared(MediaPlayer mp) { Log.v(LOGTAG, "onPrepared Called"); videoWidth = mp.getVideoWidth(); videoHeight = mp.getVideoHeight(); // 스크린 사이즈 구하기 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; if (videoWidth > screenWidth || videoHeight > screenHeight) { float heightRatio = (float) videoHeight / (float) screenHeight; float widthRatio = (float) videoWidth / (float) screenWidth; if (heightRatio > 1 || widthRatio > 1) { if (heightRatio > widthRatio) { videoHeight = (int) Math.ceil((float) videoHeight / (float) heightRatio); videoWidth = (int) Math.ceil((float) videoWidth / (float) heightRatio); } else { videoHeight = (int) Math.ceil((float) videoHeight / (float) widthRatio); videoWidth = (int) Math.ceil((float) videoWidth / (float) widthRatio); } } } else { videoHeight = screenHeight; videoWidth = screenWidth; } // surfaceView.setLayoutParams(new FrameLayout.LayoutParams(videoWidth, // videoHeight - 75)); mp.start(); // 미디어 플레이어의 컨트롤러를 설정하고 보이기 controller.setMediaPlayer(this); controller.setAnchorView(this.findViewById(R.id.controllerView)); controller.setEnabled(true); controller.show(); }
@Override public void showVideoMassage(String path) { if (player == null) return; MediaPlayer mediaData = player; // 获取视频时间 long ms = mediaData.getDuration(); String Duration = getResources().getString(R.string.duration) + mHandler.toDuration((long) ms) + "\n"; // 获取视频分辨率 String wVideo = String.valueOf(mediaData.getVideoWidth()); String hVideo = String.valueOf(mediaData.getVideoHeight()); String Resolution = getResources().getString(R.string.resolution) + wVideo + "*" + hVideo + "\n"; // 获取视频大小 String Size = getResources().getString(R.string.size) + mHandler.toSize(new File(path).length()) + "\n"; String Display = Size + Duration + Resolution; mPreview.setText(Display); }
public void onPrepared(MediaPlayer mediaPlayer) { setCurrentState(STATE_PREPARED); notifyPreparedListener(mediaPlayer); try { mVideoWidth = mediaPlayer.getVideoWidth(); mVideoHeight = mediaPlayer.getVideoHeight(); mDuration = mediaPlayer.getDuration(); } catch (IllegalStateException e) { Log.e(TAG, "MediaPlayer object has been released. Exception : " + e); return; } // TODO : seek if (mVideoWidth == 0 || mVideoHeight == 0) { // TODO : report size issue. if (mIntentState == STATE_PLAYING) { start(mSegmentId); } } else { if (mIntentState == STATE_PLAYING) { start(mSegmentId); } } }
private int getPictureWidth() { if (mmediaplayer != null && mPlayStatus != VideoConst.PLAY_STATUS_UNKNOW) return mmediaplayer.getVideoWidth(); return 0; }
public void onMeasure(int specwidth, int specheight) { // Since super.onMeasure uses the aspect ratio of the video being // played, it is not called. // http://grepcode.com/file/repository.grepcode.com/java/ext/ // com.google.android/android/2.2.2_r1/android/widget/VideoView.java // #VideoView.onMeasure%28int%2Cint%29 // Log messages in this method are not commented out for testing the // changes // on other devices. Log.i( "VideoPlayer..onMeasure", "AI setting dimensions as:" + forcedWidth + ":" + forcedHeight); Log.i( "VideoPlayer..onMeasure", "Dimenions from super>>" + MeasureSpec.getSize(specwidth) + ":" + MeasureSpec.getSize(specheight)); // The VideoPlayer's dimensions must always be some non-zero number. int width = ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH; int height = ComponentConstants.VIDEOPLAYER_PREFERRED_HEIGHT; switch (forcedWidth) { case LENGTH_FILL_PARENT: switch (MeasureSpec.getMode(specwidth)) { case MeasureSpec.EXACTLY: case MeasureSpec.AT_MOST: width = MeasureSpec.getSize(specwidth); break; case MeasureSpec.UNSPECIFIED: try { width = ((View) getParent()).getMeasuredWidth(); } catch (ClassCastException cast) { width = ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH; } catch (NullPointerException nullParent) { width = ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH; } } break; case LENGTH_PREFERRED: if (mFoundMediaPlayer) { try { width = mVideoPlayer.getVideoWidth(); Log.i("VideoPlayer.onMeasure", "Got width from MediaPlayer>" + width); } catch (NullPointerException nullVideoPlayer) { Log.e( "VideoPlayer..onMeasure", "Failed to get MediaPlayer for width:\n" + nullVideoPlayer.getMessage()); width = ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH; } } else { } break; default: width = forcedWidth; } switch (forcedHeight) { case LENGTH_FILL_PARENT: switch (MeasureSpec.getMode(specheight)) { case MeasureSpec.EXACTLY: case MeasureSpec.AT_MOST: height = MeasureSpec.getSize(specheight); break; case MeasureSpec.UNSPECIFIED: // Use height from ComponentConstants // The current measuring of components ignores FILL_PARENT for height, // and does not actually fill the height of the parent container. } break; case LENGTH_PREFERRED: if (mFoundMediaPlayer) { try { height = mVideoPlayer.getVideoHeight(); Log.i("VideoPlayer.onMeasure", "Got height from MediaPlayer>" + height); } catch (NullPointerException nullVideoPlayer) { Log.e( "VideoPlayer..onMeasure", "Failed to get MediaPlayer for height:\n" + nullVideoPlayer.getMessage()); height = ComponentConstants.VIDEOPLAYER_PREFERRED_HEIGHT; } } break; default: height = forcedHeight; } // Forces the video playing in the VideoView to scale. // Some Android devices though will not scale the video playing. Log.i("VideoPlayer.onMeasure", "Setting dimensions to:" + width + "x" + height); getHolder().setFixedSize(width, height); setMeasuredDimension(width, height); }