Skip to content

Commit

Permalink
Merge pull request #96 from ksvc/updateVer_2.2.2.5
Browse files Browse the repository at this point in the history
update multicanvasdemo version to 2.2.2.5
  • Loading branch information
chriszeng87 authored Mar 27, 2018
2 parents 2367005 + 2878531 commit 2c77995
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 104 deletions.
8 changes: 4 additions & 4 deletions demo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
8 changes: 4 additions & 4 deletions demo/multicanvasdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
2 changes: 1 addition & 1 deletion demo/multicanvasdemo/src/main/assets/AuthForTest.pkg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
EplivEyFlzQI5X3Jl9RlxMBtZ4YfL81k1ltn8dOKZ6zBWkcBd06gSrPNyPZvxomaHYZzogQ4c35kcikPu+KgRsL1w/UAPQkLk/KOKUg5cCxKgfUghXDHY16xwxUfgBdU26jiJUYNem0wZxHKI+fgfNUKHnvaSiGqqo1uBhLJerA=H1vDZda3qkvVgv2s7w5ERhqf02avp9k1BkhLi+ygKL2dmKi+YApw1ngI6n1I5O2Ap/m0u+NnZuG8lZpqwTBWoF4GPjU8hT+fOKrQFCd5y+1xl1BDi6MwDwe57aycJe6aklSbIr46zkvRUMsrwKHQNtJKh6wAT+yRUGjXPVTzEvc=
qTdLGiZ3ss2/l/7TB85Mdl6Ro5eerjV5HJFLNFXTqjz4yV9SRv2qBxj+NB9a82OV0rTVSA96eKmTITsG7QpoDi3ed4tulCdIZBtzxtqw5kDQwTWRUubOlLeAwRusHmcy+WyKdq67nfCHVktpi5GsFyCQVyAdxy8aobnFrPAdaj0=TcFt/lwv/hi3uX3IR+9XTGSth8So6ywKy8T5qeRZsWsa4ow6u7SMCAFTgx3nXkxeVXRj4v9OgIbAJYKr9J1+qWCBrYPE/Z0qi89oNgKyPyQp1n1r0FC0zm9xutDuanXJJSjID1KIa/aaHp5Uyt5ksDk7mnMr+ydI51OjS57iKu4=
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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()) {
Expand Down Expand Up @@ -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 {
//最后一次可适当降低分辨率
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -48,6 +50,7 @@
import android.widget.Toast;

import java.io.File;
import java.io.IOException;

/**
* demo for model record
Expand All @@ -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;
Expand All @@ -89,7 +91,6 @@ public class MultiCanvasRecordActivity extends Activity implements

//录制kit
private KSYRecordKit mKSYRecordKit;
private KSYMediaPlayer mMediaPlayer;

private Handler mMainHandler;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -351,19 +349,22 @@ public void onResume() {
// camera may be occupied by other app in background
checkPermission();

mPlayerPreview.runInForeground();
//如果当前正在录制,恢复播放
if (mIsFileRecording && !TextUtils.isEmpty(mPlayUrl)) {
mMediaPlayer.start();
mPlayerPreview.start();
}
}

@Override
public void onPause() {
super.onPause();
mKSYRecordKit.onPause();
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.pause();
mPlayerPreview.runInBackground(false);
if (mPlayerPreview.isPlaying()) {
mPlayerPreview.pause();
}

}

@Override
Expand Down Expand Up @@ -488,7 +489,8 @@ private void startRecord(int index) {

//开始之前视频的播放
if (!TextUtils.isEmpty(mPlayUrl)) {
mMediaPlayer.start();
//mMediaPlayer.start();
mPlayerPreview.start();
}
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
};

Expand All @@ -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;
Expand All @@ -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**************************************/
Expand Down
9 changes: 4 additions & 5 deletions demo/multicanvasdemo/src/main/res/layout/edit_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.opengl.GLSurfaceView
android:id="@+id/edit_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<SurfaceView
android:id="@+id/player_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextureView
android:id="@+id/edit_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

<include
Expand Down
Loading

0 comments on commit 2c77995

Please sign in to comment.