-
Notifications
You must be signed in to change notification settings - Fork 246
scaleVideo
wshichang edited this page Feb 10, 2017
·
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);
// 拉伸模式(1.7.2及以上版本)
player.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALEING_MODE_SCALE_TO_FILL);
调用时机:
- 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();
}
}