-
Notifications
You must be signed in to change notification settings - Fork 246
scaleVideo
xinbaicheng edited this page Oct 12, 2016
·
10 revisions
播放器类KSYMediaPlayer提供接口 setVideoScalingMode,可以设置视频伸缩模式
KSYMediaPlayer player = KSYMediaPlayer.Builder(mContext).build();
// 填充模式
player.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
// 裁剪模式
player.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
调用时机:
- onPrepared回调时
- 屏幕旋转时
使用硬解
功能时建议使用KSYTextureView
它提供了与KSYMediaPlayer一致的接口,并能在硬解
时实现旋转、缩放、截图等功能
播放器的部分布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/player_black">
<com.ksyun.media.player.KSYTextureView
android:id="@+id/player_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
播放器的部分代码
private KSYTextureView mVideoSurfaceView;
mVideoSurfaceView = (KSYTextureView) findViewById(R.id.player_surface);
private IMediaPlayer.OnPreparedListener mOnPreparedListener = new IMediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(IMediaPlayer mp) {
if (ksyMediaPlayer != null) {
if(mVideoSurfaceView != null)
{
mVideoSurfaceView.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
}
ksyMediaPlayer.start();
}
}