* commit '0318d6bfd3882b3f6fb82b03aca496e68c36d1f9': Fix the aspect ratio for full screen playing
This commit is contained in:
@ -25,7 +25,30 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
implements MediaPlayerControl, MediaPlayer.OnPreparedListener,
|
implements MediaPlayerControl, MediaPlayer.OnPreparedListener,
|
||||||
View.OnTouchListener {
|
View.OnTouchListener {
|
||||||
|
|
||||||
private SurfaceView mSurfaceView;
|
// Add this sub-class to handle the resizing when rotating screen.
|
||||||
|
private class VideoSurfaceView extends SurfaceView {
|
||||||
|
|
||||||
|
public VideoSurfaceView(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
|
||||||
|
int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
|
||||||
|
if (mVideoWidth > 0 && mVideoHeight > 0) {
|
||||||
|
if ( mVideoWidth * height > width * mVideoHeight ) {
|
||||||
|
height = width * mVideoHeight / mVideoWidth;
|
||||||
|
} else if ( mVideoWidth * height < width * mVideoHeight ) {
|
||||||
|
width = height * mVideoWidth / mVideoHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setMeasuredDimension(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This view will contain the video.
|
||||||
|
private VideoSurfaceView mVideoSurfaceView;
|
||||||
|
|
||||||
// We need the full screen state to decide which surface to render to and
|
// We need the full screen state to decide which surface to render to and
|
||||||
// when to create the MediaPlayer accordingly.
|
// when to create the MediaPlayer accordingly.
|
||||||
@ -51,6 +74,11 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
// The container for the progress view and video view
|
// The container for the progress view and video view
|
||||||
private static FrameLayout mLayout;
|
private static FrameLayout mLayout;
|
||||||
|
|
||||||
|
// The video size will be ready when prepared. Used to make sure the aspect
|
||||||
|
// ratio is correct.
|
||||||
|
private int mVideoWidth;
|
||||||
|
private int mVideoHeight;
|
||||||
|
|
||||||
SurfaceHolder.Callback mSHCallback = new SurfaceHolder.Callback()
|
SurfaceHolder.Callback mSHCallback = new SurfaceHolder.Callback()
|
||||||
{
|
{
|
||||||
public void surfaceChanged(SurfaceHolder holder, int format,
|
public void surfaceChanged(SurfaceHolder holder, int format,
|
||||||
@ -82,14 +110,16 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public SurfaceView getSurfaceView() {
|
private SurfaceView getSurfaceView() {
|
||||||
return mSurfaceView;
|
return mVideoSurfaceView;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTML5VideoFullScreen(Context context, int videoLayerId, int position,
|
HTML5VideoFullScreen(Context context, int videoLayerId, int position,
|
||||||
boolean autoStart) {
|
boolean autoStart) {
|
||||||
mSurfaceView = new SurfaceView(context);
|
mVideoSurfaceView = new VideoSurfaceView(context);
|
||||||
mFullScreenMode = FULLSCREEN_OFF;
|
mFullScreenMode = FULLSCREEN_OFF;
|
||||||
|
mVideoWidth = 0;
|
||||||
|
mVideoHeight = 0;
|
||||||
init(videoLayerId, position, autoStart);
|
init(videoLayerId, position, autoStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +131,7 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
private void attachMediaController() {
|
private void attachMediaController() {
|
||||||
if (mPlayer != null && mMediaController != null) {
|
if (mPlayer != null && mMediaController != null) {
|
||||||
mMediaController.setMediaPlayer(this);
|
mMediaController.setMediaPlayer(this);
|
||||||
mMediaController.setAnchorView(mSurfaceView);
|
mMediaController.setAnchorView(mVideoSurfaceView);
|
||||||
//Will be enabled when prepared
|
//Will be enabled when prepared
|
||||||
mMediaController.setEnabled(false);
|
mMediaController.setEnabled(false);
|
||||||
}
|
}
|
||||||
@ -112,8 +142,7 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
mPlayer.setDisplay(mSurfaceHolder);
|
mPlayer.setDisplay(mSurfaceHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void prepareForFullScreen() {
|
||||||
public void prepareForFullScreen() {
|
|
||||||
// So in full screen, we reset the MediaPlayer
|
// So in full screen, we reset the MediaPlayer
|
||||||
mPlayer.reset();
|
mPlayer.reset();
|
||||||
setMediaController(new MediaController(mProxy.getContext()));
|
setMediaController(new MediaController(mProxy.getContext()));
|
||||||
@ -134,7 +163,7 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
public void onPrepared(MediaPlayer mp) {
|
public void onPrepared(MediaPlayer mp) {
|
||||||
super.onPrepared(mp);
|
super.onPrepared(mp);
|
||||||
|
|
||||||
mSurfaceView.setOnTouchListener(this);
|
mVideoSurfaceView.setOnTouchListener(this);
|
||||||
// Get the capabilities of the player for this stream
|
// Get the capabilities of the player for this stream
|
||||||
Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
|
Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
|
||||||
MediaPlayer.BYPASS_METADATA_FILTER);
|
MediaPlayer.BYPASS_METADATA_FILTER);
|
||||||
@ -165,6 +194,11 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
mLayout.removeView(mProgressView);
|
mLayout.removeView(mProgressView);
|
||||||
mProgressView = null;
|
mProgressView = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mVideoWidth = mp.getVideoWidth();
|
||||||
|
mVideoHeight = mp.getVideoHeight();
|
||||||
|
// This will trigger the onMeasure to get the display size right.
|
||||||
|
mVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -202,11 +236,11 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
mPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
|
mPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
|
||||||
mProxy = proxy;
|
mProxy = proxy;
|
||||||
|
|
||||||
mSurfaceView.getHolder().addCallback(mSHCallback);
|
mVideoSurfaceView.getHolder().addCallback(mSHCallback);
|
||||||
mSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
mVideoSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||||
mSurfaceView.setFocusable(true);
|
mVideoSurfaceView.setFocusable(true);
|
||||||
mSurfaceView.setFocusableInTouchMode(true);
|
mVideoSurfaceView.setFocusableInTouchMode(true);
|
||||||
mSurfaceView.requestFocus();
|
mVideoSurfaceView.requestFocus();
|
||||||
|
|
||||||
// Create a FrameLayout that will contain the VideoView and the
|
// Create a FrameLayout that will contain the VideoView and the
|
||||||
// progress view (if any).
|
// progress view (if any).
|
||||||
|
@ -243,16 +243,9 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SurfaceView getSurfaceView() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void decideDisplayMode() {
|
public void decideDisplayMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepareForFullScreen() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getReadyToUseSurfTex() {
|
public boolean getReadyToUseSurfTex() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user