如何在Android上旋转SurfaceView ?



我正在使用vlcandoid库。一开始我使用了TextureView,这样我就可以随心所欲地旋转玩家。但是TextureView在一些旧设备上表现不佳,FPS下降,所以我必须切换回SurfaceView。但是我不能再旋转播放器了

我试图通过requestOrientation()设置活动的方向,但我使用的设备无法将其方向设置为REVERSE_LANDSCAPE

我已经尝试设置VLC选项,但它也不工作:

args.add("--video-filter=rotate")
args.add("--rotate-angle=180")

所以我唯一的选择就是旋转VLCLayout的SurfaceView。但是我试着将它的方向设置为180f,但是它也不起作用。

你知道如何旋转SurfaceView吗?谢谢你。

private void changeMediaPlayerLayout(int displayW, int displayH) {
if (mMediaPlayer.isReleased()) return;
/* Change the video placement using the MediaPlayer API */
switch (mCurrentScaleType) {
case SURFACE_BEST_FIT:
mMediaPlayer.setAspectRatio(null);
mMediaPlayer.setScale(0);
break;
case SURFACE_FIT_SCREEN:
case SURFACE_FILL: {
IMedia.VideoTrack vtrack = mMediaPlayer.getCurrentVideoTrack();
if (vtrack == null)
return;
final boolean videoSwapped = vtrack.orientation == IMedia.VideoTrack.Orientation.LeftBottom
|| vtrack.orientation == IMedia.VideoTrack.Orientation.RightTop;
if (mCurrentScaleType == MediaPlayer.ScaleType.SURFACE_FIT_SCREEN) {
int videoW = vtrack.width;
int videoH = vtrack.height;
if (videoSwapped) {
int swap = videoW;
videoW = videoH;
videoH = swap;
}
if (vtrack.sarNum != vtrack.sarDen)
videoW = videoW * vtrack.sarNum / vtrack.sarDen;
float ar = videoW / (float) videoH;
float dar = displayW / (float) displayH;
float scale;
if (dar >= ar)
scale = displayW / (float) videoW; /* horizontal */
else
scale = displayH / (float) videoH; /* vertical */
mMediaPlayer.setScale(scale);
mMediaPlayer.setAspectRatio(null);
} else {
mMediaPlayer.setScale(0);
mMediaPlayer.setAspectRatio(!videoSwapped ? ""+displayW+":"+displayH
: ""+displayH+":"+displayW);
}
break;
}
case SURFACE_16_9:
mMediaPlayer.setAspectRatio("16:9");
mMediaPlayer.setScale(0);
break;
case SURFACE_4_3:
mMediaPlayer.setAspectRatio("4:3");
mMediaPlayer.setScale(0);
break;
case SURFACE_ORIGINAL:
mMediaPlayer.setAspectRatio(null);
mMediaPlayer.setScale(1);
break;
}
}

从https://code.videolan.org/videolan/vlc-android/-/blob/master/libvlc/src/org/videolan/libvlc/VideoHelper.java

你需要使用比例和纵横比函数。

相关内容

  • 没有找到相关文章

最新更新