我想在横向模式下继续播放视频,同时按fullscreen
按钮
我使用了TextureView
,并尝试使用VideoView
和SurfaceView
只有视图应该是横向而不是像screenOrientation=landscape in manifest
这是肖像模式
现在发生的事情
这是代码
if (!isFullScreen()) {
isFullScreen=true;
sizePortait[0]=textureView.getWidth();
sizePortait[1]=textureView.getHeight();
// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mlayoutVideoTrainig.getHeight(),mlayoutVideoTrainig.getWidth());
textureView.setRotation(90);
textureView.setLayoutParams(params);
adjustAspectRatio(mlayoutVideoTrainig.getHeight(), mlayoutVideoTrainig.getWidth());
}
/**
* Sets the TextureView transform to preserve the aspect ratio of the video.
*/
private void adjustAspectRatio(int videoWidth, int videoHeight) {
int viewWidth = videoWidth;
int viewHeight = videoHeight;
double aspectRatio = (double) videoHeight / videoWidth;
int newWidth, newHeight;
if (viewHeight > (int) (viewWidth * aspectRatio)) {
// limited by narrow width; restrict height
newWidth = viewWidth;
newHeight = (int) (viewWidth * aspectRatio);
} else {
// limited by short height; restrict width
newWidth = (int) (viewHeight / aspectRatio);
newHeight = viewHeight;
}
int xoff = (viewWidth - newWidth) / 2;
int yoff = (viewHeight - newHeight) / 2;
Log.v(TAG, "video=" + videoWidth + "x" + videoHeight +
" view=" + viewWidth + "x" + viewHeight +
" newView=" + newWidth + "x" + newHeight +
" off=" + xoff + "," + yoff);
Matrix txform = new Matrix();
textureView.getTransform(txform);
txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
//txform.postRotate(10); // just for fun
txform.postTranslate(xoff, yoff);
textureView.setTransform(txform);
}
XML文件
内部片段
<FrameLayout
android:id="@+id/videoSurfaceContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextureView
android:id="@+id/videoSurface"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
</FrameLayout>
<TextView
android:id="@+id/txtHowToObtain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="@string/how_to_obtain_the_best_mortgage_rate"
android:textColor="@color/myAccentColor"
android:textSize="22sp" />