横向模式下的视频,同时按下全屏按钮

时间:2015-04-29 14:25:31

标签: android android-videoview landscape textureview

我想在横向模式下继续播放视频,同时按fullscreen按钮 我使用了TextureView,并尝试使用VideoViewSurfaceView

只有视图应该是横向而不是像screenOrientation=landscape in manifest

这样的整个活动

这是肖像模式

This is Portrait mode

现在发生的事情

what happening right now

这是代码

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" />

0 个答案:

没有答案