|
@@ -23,12 +23,15 @@ import android.widget.FrameLayout;
|
|
|
import android.widget.SeekBar;
|
|
|
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
import com.cooleshow.base.constanst.Constants;
|
|
|
import com.cooleshow.base.constanst.UploadConstants;
|
|
|
import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
import com.cooleshow.base.utils.FileUtils;
|
|
|
import com.cooleshow.base.utils.GlideUtils;
|
|
|
+import com.cooleshow.base.utils.GsonUtils;
|
|
|
+import com.cooleshow.base.utils.JumpUtils;
|
|
|
import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.base.utils.MyFileUtils;
|
|
|
import com.cooleshow.base.utils.NumberUtils;
|
|
@@ -43,6 +46,7 @@ import com.cooleshow.base.widgets.dialog.CommonConfirmDialog2;
|
|
|
import com.cooleshow.musicmerge.R;
|
|
|
import com.cooleshow.musicmerge.bean.MusicDataBean;
|
|
|
import com.cooleshow.musicmerge.bean.MusicInfoBean;
|
|
|
+import com.cooleshow.musicmerge.bean.MusicMergeConfigBean;
|
|
|
import com.cooleshow.musicmerge.callback.ResultCallback;
|
|
|
import com.cooleshow.musicmerge.contract.MusicFileHandleContract;
|
|
|
import com.cooleshow.musicmerge.databinding.AcMusicHandleLayoutBinding;
|
|
@@ -69,6 +73,8 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
public static final int REQUEST_CODE_LOCAL = 0x19;
|
|
|
public static final int REQUEST_CODE_LOCAL_VIDEO_COVER = 0x20;
|
|
|
public static final int REQUEST_CODE_VIDEO_COVER = 0x29;
|
|
|
+
|
|
|
+ public static final int MAX_ADJUSTMENT = 10;
|
|
|
private CustomPlayer player1;
|
|
|
private CustomPlayer player2;
|
|
|
private String accompanyUrl;
|
|
@@ -99,6 +105,10 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
private static final int MAX_PROGRESS = 100;
|
|
|
private int currentStep = 0;
|
|
|
|
|
|
+ private int firstPlayDuration = 0;
|
|
|
+ private int secondPlayDuration = 0;
|
|
|
+ private int defaultDelay = 0;//此字段用于录音文件前面缓冲以及设备延迟造成的空白延迟字段
|
|
|
+ private int evaluateDelay = 0;//此字段记录给IOS使用
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
@@ -119,6 +129,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
mSettingFragment = new MusicHandleSettingFragment();
|
|
|
Bundle bundle = new Bundle();
|
|
|
bundle.putString("accompanyUrl", accompanyUrl);
|
|
|
+ bundle.putInt("defaultDelay", defaultDelay);
|
|
|
mSettingFragment.setArguments(bundle);
|
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.fl_setting, mSettingFragment).commitAllowingStateLoss();
|
|
|
}
|
|
@@ -165,6 +176,8 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
mRecordId = getIntent().getStringExtra("recordId");
|
|
|
worksId = getIntent().getStringExtra("worksId");
|
|
|
imgCover = getIntent().getStringExtra("coverImg");
|
|
|
+ defaultDelay = getIntent().getIntExtra("defaultDelay", 0);
|
|
|
+ evaluateDelay = getIntent().getIntExtra("evaluateDelay", 0);
|
|
|
|
|
|
loadCover();
|
|
|
if (TextUtils.isEmpty(mRecordId)) {
|
|
@@ -397,7 +410,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
}
|
|
|
|
|
|
private void toNotify(String url) {
|
|
|
- String configJson = mSettingFragment.getConfigJson();
|
|
|
+ String configJson = mSettingFragment.getConfigJson(defaultDelay, evaluateDelay);
|
|
|
MusicInfoBean value = mViewModel.getMusicInfoLiveData().getValue();
|
|
|
String videoCover = "";
|
|
|
String cover = imgCover;
|
|
@@ -417,7 +430,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
|
|
|
private void toNotifyDraft(String url) {
|
|
|
if (mSettingFragment != null) {
|
|
|
- String configJson = mSettingFragment.getConfigJson();
|
|
|
+ String configJson = mSettingFragment.getConfigJson(defaultDelay, evaluateDelay);
|
|
|
presenter.saveDraft(mRecordId, url, accompanyUrl, imgCover, configJson);
|
|
|
}
|
|
|
}
|
|
@@ -459,8 +472,10 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- LOG.i("progressPercent:" + progressPercent);
|
|
|
- toUpdateLoadingText(getCurrentProgress(progressPercent), getString(R.string.video_merge_tip));
|
|
|
+ if (currentStep == 0) {//这个进度有延迟,可能不准确,如果到了下一个步骤了就不再触发更新
|
|
|
+ LOG.i("progressPercent:" + progressPercent);
|
|
|
+ toUpdateLoadingText(getCurrentProgress(progressPercent), getString(R.string.video_merge_tip));
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -518,8 +533,10 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- LOG.i("progressPercent:" + progressPercent);
|
|
|
- toUpdateLoadingText(getCurrentProgress(progressPercent), getString(R.string.audio_merge_tip));
|
|
|
+ if (currentStep == 0) {//这个进度有延迟,可能不准确,如果到了下一个步骤了就不再触发更新
|
|
|
+ LOG.i("progressPercent:" + progressPercent);
|
|
|
+ toUpdateLoadingText(getCurrentProgress(progressPercent), getString(R.string.audio_merge_tip));
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -544,7 +561,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
int cu = player1.getCu();
|
|
|
LOG.i("pq", "cu:" + cu);
|
|
|
LOG.i("pq", "currentOffsetValue:" + value);
|
|
|
- int seekResult2 = cu - value;
|
|
|
+ int seekResult2 = countAccompanyPosition(cu);
|
|
|
LOG.i("pq", "seekResult2:" + seekResult2);
|
|
|
player2.seekTo(seekResult2);
|
|
|
}
|
|
@@ -554,14 +571,19 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
float percent = progress * 1.0f / viewBinding.seekPlay.getMax();
|
|
|
int seekResult = (int) (player1.getTotal() * percent);
|
|
|
LOG.i("pq", "seekResult:" + seekResult);
|
|
|
- int currentOffsetValue = mSettingFragment.getCurrentOffsetValue();
|
|
|
- LOG.i("pq", "currentOffsetValue:" + currentOffsetValue);
|
|
|
- int seekResult2 = seekResult - currentOffsetValue;
|
|
|
+ int seekResult2 = countAccompanyPosition(seekResult);
|
|
|
LOG.i("pq", "seekResult2:" + seekResult2);
|
|
|
player1.seekTo(seekResult);
|
|
|
player2.seekTo(seekResult2);
|
|
|
}
|
|
|
|
|
|
+ private int countAccompanyPosition(int recordPosition) {
|
|
|
+ int currentOffsetValue = mSettingFragment.getCurrentOffsetValue();
|
|
|
+ LOG.i("pq", "currentOffsetValue:" + currentOffsetValue);
|
|
|
+ int exceptPosition = recordPosition + currentOffsetValue;
|
|
|
+ return exceptPosition;
|
|
|
+ }
|
|
|
+
|
|
|
private void initPlayer() {
|
|
|
player1 = new CustomPlayer("luzhi");
|
|
|
player2 = new CustomPlayer("伴奏");
|
|
@@ -571,6 +593,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
if (!checkActivityExist()) {
|
|
|
return;
|
|
|
}
|
|
|
+ toShowDelay();
|
|
|
String s = TimeUtils.msToTime(progress);
|
|
|
viewBinding.tvCurrentProgress.setText(s);
|
|
|
int maxProgress = viewBinding.seekPlay.getMax();
|
|
@@ -583,10 +606,10 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
if (!checkActivityExist()) {
|
|
|
return;
|
|
|
}
|
|
|
+ firstPlayDuration = duration;
|
|
|
String s = TimeUtils.msToTime(duration);
|
|
|
viewBinding.tvTotalProgress.setText(s);
|
|
|
- setVolume();
|
|
|
- updatePlayStatus();
|
|
|
+ toRealPlay();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -626,8 +649,10 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
|
|
|
@Override
|
|
|
public void onPrepared(int duration) {
|
|
|
+ secondPlayDuration = duration;
|
|
|
String s = TimeUtils.msToTime(duration);
|
|
|
viewBinding.tvTotalProgress2.setText(s);
|
|
|
+ toRealPlay();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -647,6 +672,46 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void toShowDelay() {
|
|
|
+ int cu = player1.getCu();
|
|
|
+ int cu1 = player2.getCu();
|
|
|
+ int dif = cu1 - cu;
|
|
|
+ String text = "演奏进度:" + cu + "\n伴奏进度:" + cu1 + "\n差值:" + dif;
|
|
|
+ viewBinding.tvDelayText.setText(text);
|
|
|
+ if (!player1.isPlaying()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LOG.i("pq", "dif:" + dif);
|
|
|
+
|
|
|
+ int expectDelay = dif - mSettingFragment.getCurrentOffsetValue();
|
|
|
+ LOG.i("pq", "expectDelay:" + expectDelay);
|
|
|
+ int difAbs = Math.abs(expectDelay);
|
|
|
+ if (difAbs > MAX_ADJUSTMENT) {
|
|
|
+ float s = difAbs / 1000f;
|
|
|
+ if (expectDelay > 0) {
|
|
|
+ player1.setSpeed(1.0f + s);
|
|
|
+ player2.setSpeed(1.0f - s);
|
|
|
+ } else {
|
|
|
+ player1.setSpeed(1.0f - s);
|
|
|
+ player2.setSpeed(1.0f + s);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ player1.setSpeed(1.0f);
|
|
|
+ player2.setSpeed(1.0f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toRealPlay() {
|
|
|
+ if (firstPlayDuration != 0 && secondPlayDuration != 0) {
|
|
|
+ player1.resetToPrepare();
|
|
|
+ player2.resetToPrepare();
|
|
|
+ player1.start();
|
|
|
+ player2.start();
|
|
|
+ setVolume();
|
|
|
+ updatePlayStatus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void setVolume() {
|
|
|
if (mSettingFragment != null) {
|
|
|
float originalVolume = mSettingFragment.getOriginalVolume();
|
|
@@ -867,13 +932,12 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
int id = v.getId();
|
|
|
if (id == R.id.iv_play) {
|
|
|
if (player1.isPlaying()) {
|
|
|
- player1.pause();
|
|
|
- player2.pause();
|
|
|
+ pausePlay();
|
|
|
} else {
|
|
|
player1.resume();
|
|
|
player2.resume();
|
|
|
+ updatePlayStatus();
|
|
|
}
|
|
|
- updatePlayStatus();
|
|
|
return;
|
|
|
}
|
|
|
if (id == R.id.iv_unfold_sentting) {
|
|
@@ -896,6 +960,8 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
if (player1.isPlaying()) {
|
|
|
player1.pause();
|
|
|
player2.pause();
|
|
|
+ //暂停的时候需要校准一次,防止定时器触发
|
|
|
+ aligningAccompany(mSettingFragment.getCurrentOffsetValue());
|
|
|
}
|
|
|
updatePlayStatus();
|
|
|
}
|
|
@@ -1055,7 +1121,7 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
accompanyUrl = data.getAccompanyUrl();
|
|
|
if (mSettingFragment != null) {
|
|
|
if (!TextUtils.isEmpty(jsonConfig)) {
|
|
|
- mSettingFragment.applyConfig(jsonConfig);
|
|
|
+ toApplyConfig(jsonConfig);
|
|
|
}
|
|
|
mSettingFragment.setAccompanyUrl(accompanyUrl);
|
|
|
}
|
|
@@ -1071,6 +1137,17 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void toApplyConfig(String jsonConfig) {
|
|
|
+ try {
|
|
|
+ MusicMergeConfigBean musicMergeConfigBean = GsonUtils.fromJson(jsonConfig, MusicMergeConfigBean.class);
|
|
|
+ defaultDelay = musicMergeConfigBean.getDefaultDelay();
|
|
|
+ evaluateDelay = musicMergeConfigBean.getEvaluateDelay();
|
|
|
+ mSettingFragment.applyConfig(musicMergeConfigBean);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void saveWorksDraftSuccess() {
|
|
|
if (!checkActivityExist()) {
|
|
@@ -1085,12 +1162,52 @@ public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBind
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- hideLoading();
|
|
|
+ if (isNeedTip()) {
|
|
|
+ showOtherTipDialog();
|
|
|
+ }
|
|
|
}
|
|
|
- }, 1500);
|
|
|
+ }, 500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isNeedTip() {
|
|
|
+ //云教练进来的需要提示 作品草稿过来的不需要
|
|
|
+ return TextUtils.isEmpty(worksId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showOtherTipDialog() {
|
|
|
+ CommonConfirmDialog2 commonConfirmDialog = new CommonConfirmDialog2(this);
|
|
|
+ commonConfirmDialog.setWidth(SizeUtils.dp2px(387));
|
|
|
+ commonConfirmDialog.show();
|
|
|
+ commonConfirmDialog.setTitle("提示");
|
|
|
+ commonConfirmDialog.setContent("已成功保存到草稿,草稿7天未发布\n将自动清理。");
|
|
|
+ commonConfirmDialog.setCancelText("确认");
|
|
|
+ commonConfirmDialog.setConfirmText("查看草稿");
|
|
|
+ commonConfirmDialog.setOnCancelClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ commonConfirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
+ //从首页个人中心跳转我的作品
|
|
|
+ JumpUtils.jumpMain(4);
|
|
|
+ goMyWorks();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void goMyWorks() {
|
|
|
+ ARouter.getInstance().build(RouterPath.Homework.MY_WORK)
|
|
|
+ .withInt(Constants.MAIN_PAGE_SELECT_POTION_KEY, 1)
|
|
|
+ .navigation();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
private void showToastViewAndFinish(String tip, boolean isReCallBack) {
|
|
|
//测试lyr提出提示要在当前面提示,所以给出延迟finish
|
|
|
// viewBinding.tvToastView.setText(tip);
|