From 287853159957d76c5e918ad6025c2aea14e82ce0 Mon Sep 17 00:00:00 2001 From: XINGKAI Date: Tue, 27 Mar 2018 21:16:19 +0800 Subject: [PATCH] update multicanvasdemo version to 2.2.2.5 --- demo/app/build.gradle | 8 +- demo/multicanvasdemo/build.gradle | 8 +- .../src/main/assets/AuthForTest.pkg | 2 +- .../MultiCanvasEditActivity.java | 22 ++-- .../MultiCanvasRecordActivity.java | 107 ++++++------------ .../src/main/res/layout/edit_activity.xml | 9 +- .../src/main/res/layout/record_activity.xml | 15 +-- 7 files changed, 67 insertions(+), 104 deletions(-) diff --git a/demo/app/build.gradle b/demo/app/build.gradle index af0e9ab..a41ad3e 100644 --- a/demo/app/build.gradle +++ b/demo/app/build.gradle @@ -41,8 +41,8 @@ dependencies { implementation 'com.facebook.fresco:animated-gif:1.4.0' implementation 'com.facebook.fresco:animated-webp:1.4.0' implementation 'com.lht:paintview:1.17' - compile 'com.ksyun.media:libksysv-java:2.2.1' - compile 'com.ksyun.media:libksysv-arm64:2.2.1' - compile 'com.ksyun.media:libksysv-armv7a:2.2.1' - compile 'com.ksyun.media:libksysv-x86:2.2.1' + compile 'com.ksyun.media:libksysv-java:2.2.2' + compile 'com.ksyun.media:libksysv-arm64:2.2.2' + compile 'com.ksyun.media:libksysv-armv7a:2.2.2' + compile 'com.ksyun.media:libksysv-x86:2.2.2' } diff --git a/demo/multicanvasdemo/build.gradle b/demo/multicanvasdemo/build.gradle index 8ba6867..6c27478 100644 --- a/demo/multicanvasdemo/build.gradle +++ b/demo/multicanvasdemo/build.gradle @@ -35,8 +35,8 @@ dependencies { implementation 'com.android.support:recyclerview-v7:27.0.1' implementation 'com.tencent.bugly:crashreport:latest.release' implementation 'com.tencent.bugly:nativecrashreport:latest.release' - compile 'com.ksyun.media:libksysv-java:2.2.1' - compile 'com.ksyun.media:libksysv-arm64:2.2.1' - compile 'com.ksyun.media:libksysv-armv7a:2.2.1' - compile 'com.ksyun.media:libksysv-x86:2.2.1' + compile 'com.ksyun.media:libksysv-java:2.2.2' + compile 'com.ksyun.media:libksysv-arm64:2.2.2' + compile 'com.ksyun.media:libksysv-armv7a:2.2.2' + compile 'com.ksyun.media:libksysv-x86:2.2.2' } diff --git a/demo/multicanvasdemo/src/main/assets/AuthForTest.pkg b/demo/multicanvasdemo/src/main/assets/AuthForTest.pkg index 2809cf5..15fb767 100644 --- a/demo/multicanvasdemo/src/main/assets/AuthForTest.pkg +++ b/demo/multicanvasdemo/src/main/assets/AuthForTest.pkg @@ -1 +1 @@ -EplivEyFlzQI5X3Jl9RlxMBtZ4YfL81k1ltn8dOKZ6zBWkcBd06gSrPNyPZvxomaHYZzogQ4c35kcikPu+KgRsL1w/UAPQkLk/KOKUg5cCxKgfUghXDHY16xwxUfgBdU26jiJUYNem0wZxHKI+fgfNUKHnvaSiGqqo1uBhLJerA=H1vDZda3qkvVgv2s7w5ERhqf02avp9k1BkhLi+ygKL2dmKi+YApw1ngI6n1I5O2Ap/m0u+NnZuG8lZpqwTBWoF4GPjU8hT+fOKrQFCd5y+1xl1BDi6MwDwe57aycJe6aklSbIr46zkvRUMsrwKHQNtJKh6wAT+yRUGjXPVTzEvc= \ No newline at end of file +qTdLGiZ3ss2/l/7TB85Mdl6Ro5eerjV5HJFLNFXTqjz4yV9SRv2qBxj+NB9a82OV0rTVSA96eKmTITsG7QpoDi3ed4tulCdIZBtzxtqw5kDQwTWRUubOlLeAwRusHmcy+WyKdq67nfCHVktpi5GsFyCQVyAdxy8aobnFrPAdaj0=TcFt/lwv/hi3uX3IR+9XTGSth8So6ywKy8T5qeRZsWsa4ow6u7SMCAFTgx3nXkxeVXRj4v9OgIbAJYKr9J1+qWCBrYPE/Z0qi89oNgKyPyQp1n1r0FC0zm9xutDuanXJJSjID1KIa/aaHp5Uyt5ksDk7mnMr+ydI51OjS57iKu4= \ No newline at end of file diff --git a/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasEditActivity.java b/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasEditActivity.java index 64afee7..bc27c19 100644 --- a/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasEditActivity.java +++ b/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasEditActivity.java @@ -43,6 +43,7 @@ import android.view.LayoutInflater; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -119,7 +120,7 @@ public class MultiCanvasEditActivity extends Activity { private ImgFilterBase mComposeBeautyFilter; private ImgFilterBase mComposeEffectFilter; - private GLSurfaceView mEditPreviewView; + private TextureView mEditPreviewView; private SurfaceView mPlayerPreview; private SurfaceHolder mSurfaceHolder; private Timer mEditPreviewProgressTimer; @@ -292,7 +293,6 @@ protected void onCreate(Bundle savedInstanceState) { params.width = mEditModelPos.w_preview; params.height = mEditModelPos.h_preview; mEditPreviewView.setLayoutParams(params); - mEditPreviewView.setZOrderOnTop(true); mMainHandler = new Handler(); //init kit @@ -807,9 +807,7 @@ public void run() { if (!mIsPreviewSeekBarChanging) { long currentPosition = 0; if (!mModelFinished) { - if(MultiCanvasEditActivity.this.mEditKit.getMediaPlayer() != null) { - currentPosition = MultiCanvasEditActivity.this.mEditKit.getMediaPlayer().getCurrentPosition(); - } + currentPosition = MultiCanvasEditActivity.this.mEditKit.getCurrentPosition(); } else { if (mMediaPlayer != null) { currentPosition = mMediaPlayer.getCurrentPosition(); @@ -841,9 +839,9 @@ private void doStartCompose() { //配置合成参数 //当前模版示范比例是1:1,需要根据模版比例计算对应的resolution //例如若模版比例是4:3,480p,对应的resolution就应该设置为(480,480*3/4) - if(mComposeConfig.resolution == StreamerConstants.VIDEO_RESOLUTION_720P) { + if (mComposeConfig.resolution == StreamerConstants.VIDEO_RESOLUTION_720P) { mComposeKit.setTargetResolution(720, 720); - } else if(mComposeConfig.resolution == StreamerConstants.VIDEO_RESOLUTION_1080P) { + } else if (mComposeConfig.resolution == StreamerConstants.VIDEO_RESOLUTION_1080P) { mComposeKit.setTargetResolution(1080, 1080); } @@ -1026,7 +1024,7 @@ public void onClick(View view) { mOutEncodeByHW.setActivated(true); mOutEncodeBySW.setActivated(false); mOutVideoCRF.setEnabled(false); - if(Integer.parseInt(mOutVideoBitrate.getText().toString()) == 0) { + if (Integer.parseInt(mOutVideoBitrate.getText().toString()) == 0) { mOutVideoBitrate.setText(String.valueOf(4000)); } break; @@ -1134,7 +1132,7 @@ public void onStopTrackingTouch(SeekBar seekBar) { case R.id.edit_preview_SeekBar: int progress = seekBar.getProgress(); if (!mModelFinished) { - MultiCanvasEditActivity.this.mEditKit.getMediaPlayer().seekTo(progress, true); + MultiCanvasEditActivity.this.mEditKit.seekTo(progress); } else { if (mMediaPlayer != null) { mMediaPlayer.seekTo(seekBar.getProgress()); @@ -1150,10 +1148,10 @@ public void onStopTrackingTouch(SeekBar seekBar) { } private void confirmConfig() { - if(mConfigDialog == null) { + if (mConfigDialog == null) { mComposeConfig = new ShortVideoConfig(); } - if(mConfigDialog != null) { + if (mConfigDialog != null) { if (mOutRes720p.isActivated()) { mComposeConfig.resolution = StreamerConstants.VIDEO_RESOLUTION_720P; } else if (mOutRes1080p.isActivated()) { @@ -1196,7 +1194,7 @@ private void confirmConfig() { mComposeConfig.videoCRF = Integer.parseInt(mOutVideoCRF.getText().toString()); } else { //每次都使用推荐参数进行合成 - if(!mModelFinished) { + if (!mModelFinished) { mComposeConfig.resolution = StreamerConstants.VIDEO_RESOLUTION_1080P; } else { //最后一次可适当降低分辨率 diff --git a/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasRecordActivity.java b/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasRecordActivity.java index 62258ae..e5c41bd 100644 --- a/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasRecordActivity.java +++ b/demo/multicanvasdemo/src/main/java/com/ksyun/media/shortvideo/multicanvasdemo/MultiCanvasRecordActivity.java @@ -2,6 +2,7 @@ import com.ksyun.media.player.IMediaPlayer; import com.ksyun.media.player.KSYMediaPlayer; +import com.ksyun.media.player.KSYTextureView; import com.ksyun.media.shortvideo.kit.KSYRecordKit; import com.ksyun.media.shortvideo.multicanvasdemo.data.MultiCanvasInfo; import com.ksyun.media.shortvideo.multicanvasdemo.util.DensityUtil; @@ -39,6 +40,7 @@ import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.TextureView; import android.view.View; import android.view.Window; import android.view.WindowManager; @@ -48,6 +50,7 @@ import android.widget.Toast; import java.io.File; +import java.io.IOException; /** * demo for model record @@ -62,9 +65,8 @@ public class MultiCanvasRecordActivity extends Activity implements public static final int MIN_DURATION = 5 * 1000; //最短拍摄时长 public static final int EDIT_REQUEST_CODE = 100; - private GLSurfaceView mCameraPreviewView; - private SurfaceView mPlayerPreview; - private SurfaceHolder mSurfaceHolder; + private TextureView mCameraPreviewView; + private KSYTextureView mPlayerPreview; private CameraHintView mCameraHintView; private View mSwitchCameraView; private View mFlashView; @@ -89,7 +91,6 @@ public class MultiCanvasRecordActivity extends Activity implements //录制kit private KSYRecordKit mKSYRecordKit; - private KSYMediaPlayer mMediaPlayer; private Handler mMainHandler; @@ -146,7 +147,6 @@ protected void onCreate(Bundle savedInstanceState) { mPreviewLayout = findViewById(R.id.record_preview); mCameraPreviewView = findViewById(R.id.camera_preview); - mCameraPreviewView.setZOrderOnTop(true); mPlayerPreview = findViewById(R.id.player_preview); mBottomLayout = findViewById(R.id.bar_bottom); mTopLayout = findViewById(R.id.actionbar); @@ -250,9 +250,6 @@ public int onAddClicked(int index) { //init mMainHandler = new Handler(); mKSYRecordKit = new KSYRecordKit(this); - mMediaPlayer = new KSYMediaPlayer.Builder(this).build(); - mSurfaceHolder = mPlayerPreview.getHolder(); - mSurfaceHolder.addCallback(mSurfaceCallback); float frameRate = mRecordConfig.fps; if (frameRate > 0) { @@ -314,6 +311,7 @@ public int onAddClicked(int index) { protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case EDIT_REQUEST_CODE: + Log.e(TAG, "on onActivityResult"); //从编辑窗口返回,判断是否有编辑后的视频 if (data != null) { Bundle bundle = data.getExtras(); @@ -331,7 +329,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { mCameraPreviewView.setLayoutParams(previewParams); //更新添加录制icon的显示 mCanvasView.updateRecordView(mModelPos); - if (!TextUtils.isEmpty(mPlayUrl) && !mMediaPlayer.isPlaying()) { + if (!TextUtils.isEmpty(mPlayUrl) && !mPlayerPreview.isPlaying()) { startPlay(mPlayUrl); } break; @@ -351,9 +349,10 @@ public void onResume() { // camera may be occupied by other app in background checkPermission(); + mPlayerPreview.runInForeground(); //如果当前正在录制,恢复播放 if (mIsFileRecording && !TextUtils.isEmpty(mPlayUrl)) { - mMediaPlayer.start(); + mPlayerPreview.start(); } } @@ -361,9 +360,11 @@ public void onResume() { public void onPause() { super.onPause(); mKSYRecordKit.onPause(); - if (mMediaPlayer.isPlaying()) { - mMediaPlayer.pause(); + mPlayerPreview.runInBackground(false); + if (mPlayerPreview.isPlaying()) { + mPlayerPreview.pause(); } + } @Override @@ -488,7 +489,8 @@ private void startRecord(int index) { //开始之前视频的播放 if (!TextUtils.isEmpty(mPlayUrl)) { - mMediaPlayer.start(); + //mMediaPlayer.start(); + mPlayerPreview.start(); } } } @@ -901,31 +903,6 @@ private String getRecordFileFolder() { } /**************************player begin**************************************/ - private final SurfaceHolder.Callback mSurfaceCallback = new SurfaceHolder.Callback() { - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - Log.d(TAG, "mediaplayer surfaceChanged"); - - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - Log.d(TAG, "mediaplayer surfaceCreated"); - if (mMediaPlayer != null) { - mMediaPlayer.setDisplay(holder); - mMediaPlayer.setScreenOnWhilePlaying(true); - } - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - Log.d(TAG, "mediaplayer surfaceDestroyed"); - // 此处非常重要,必须调用!!! - if (mMediaPlayer != null) { - mMediaPlayer.setDisplay(null); - } - } - }; private IMediaPlayer.OnCompletionListener mOnCompletionListener = new IMediaPlayer.OnCompletionListener() { @Override public void onCompletion(IMediaPlayer mp) { @@ -936,13 +913,10 @@ public void onCompletion(IMediaPlayer mp) { private IMediaPlayer.OnPreparedListener mOnPreparedListener = new IMediaPlayer.OnPreparedListener() { @Override public void onPrepared(IMediaPlayer mp) { - if (mMediaPlayer != null) { - Log.d(TAG, "mediaplayer onPrepared"); - // 设置视频伸缩模式,此模式为填充模式 - mMediaPlayer.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT); - // 开始播放视频 - mMediaPlayer.start(); - } + // 设置视频伸缩模式,此模式为填充模式 + mPlayerPreview.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT); + // 开始播放视频 + mPlayerPreview.start(); } }; @@ -960,7 +934,7 @@ public boolean onInfo(IMediaPlayer iMediaPlayer, int what, int extra) { switch (what) { case KSYMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: //首帧视频来以后,暂停,开始录制后在启动播放 - mMediaPlayer.pause(); + mPlayerPreview.pause(); break; default: break; @@ -970,43 +944,34 @@ public boolean onInfo(IMediaPlayer iMediaPlayer, int what, int extra) { }; private void startPlay(String path) { - mMediaPlayer.setLooping(true); - mMediaPlayer.shouldAutoPlay(false); - mMediaPlayer.setOnCompletionListener(mOnCompletionListener); - mMediaPlayer.setOnPreparedListener(mOnPreparedListener); - mMediaPlayer.setOnInfoListener(mOnMediaInfoListener); - mMediaPlayer.setOnErrorListener(mOnMediaErrorListener); - mMediaPlayer.setDisplay(mSurfaceHolder); try { - mMediaPlayer.setDataSource(path); - mMediaPlayer.prepareAsync(); - } catch (Exception e) { + mPlayerPreview.setLooping(true); + mPlayerPreview.shouldAutoPlay(false); + mPlayerPreview.setOnCompletionListener(mOnCompletionListener); + mPlayerPreview.setOnPreparedListener(mOnPreparedListener); + mPlayerPreview.setOnInfoListener(mOnMediaInfoListener); + mPlayerPreview.setOnErrorListener(mOnMediaErrorListener); + mPlayerPreview.setDataSource(path); + mPlayerPreview.prepareAsync(); + } catch (IOException e) { e.printStackTrace(); } } private void stopPlay() { - if (mMediaPlayer != null) { - mMediaPlayer.setOnCompletionListener(null); - mMediaPlayer.setOnPreparedListener(null); - mMediaPlayer.setOnInfoListener(null); - mMediaPlayer.setOnErrorListener(null); - mMediaPlayer.stop(); - } + mPlayerPreview.setOnCompletionListener(null); + mPlayerPreview.setOnPreparedListener(null); + mPlayerPreview.setOnInfoListener(null); + mPlayerPreview.setOnErrorListener(null); + mPlayerPreview.stop(); } private void resetPlay() { - if (mMediaPlayer != null) { - mMediaPlayer.reset(); - mMediaPlayer.setDisplay(mSurfaceHolder); - } + mPlayerPreview.reset(); } private void releasePlay() { - if (mMediaPlayer != null) { - mMediaPlayer.release(); - mMediaPlayer = null; - } + mPlayerPreview.release(); } /**************************player end**************************************/ diff --git a/demo/multicanvasdemo/src/main/res/layout/edit_activity.xml b/demo/multicanvasdemo/src/main/res/layout/edit_activity.xml index 87d6a87..bcfd4dc 100644 --- a/demo/multicanvasdemo/src/main/res/layout/edit_activity.xml +++ b/demo/multicanvasdemo/src/main/res/layout/edit_activity.xml @@ -16,16 +16,15 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + + android:layout_height="match_parent" + android:background="#000000"> - + + - -