1

fullscreen我想在按下我使用过的按钮时以横向模式继续播放视频,TextureView并尝试使用VideoViewandSurfaceView

只有视图应该是景观而不是整个活动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" />
4

0 回答 0