|
@@ -0,0 +1,1131 @@
|
|
|
|
+package com.cooleshow.musicmerge.ui;
|
|
|
|
+
|
|
|
|
+import android.animation.ObjectAnimator;
|
|
|
|
+import android.content.Intent;
|
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
|
+import android.graphics.Color;
|
|
|
|
+import android.graphics.Rect;
|
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
|
+import android.media.MediaPlayer;
|
|
|
|
+import android.os.Bundle;
|
|
|
|
+import android.os.Handler;
|
|
|
|
+import android.os.Looper;
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
+import android.util.Log;
|
|
|
|
+import android.view.Gravity;
|
|
|
|
+import android.view.KeyEvent;
|
|
|
|
+import android.view.SurfaceHolder;
|
|
|
|
+import android.view.SurfaceView;
|
|
|
|
+import android.view.View;
|
|
|
|
+import android.view.animation.LinearInterpolator;
|
|
|
|
+import android.widget.FrameLayout;
|
|
|
|
+import android.widget.SeekBar;
|
|
|
|
+
|
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
|
+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.LOG;
|
|
|
|
+import com.cooleshow.base.utils.MyFileUtils;
|
|
|
|
+import com.cooleshow.base.utils.NumberUtils;
|
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
|
+import com.cooleshow.base.utils.TimeUtils;
|
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
|
+import com.cooleshow.base.utils.helper.upload.UploadHelper;
|
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
|
|
|
|
+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.callback.ResultCallback;
|
|
|
|
+import com.cooleshow.musicmerge.contract.MusicFileHandleContract;
|
|
|
|
+import com.cooleshow.musicmerge.databinding.AcMusicHandleLayoutBinding;
|
|
|
|
+import com.cooleshow.musicmerge.helper.MixHelper;
|
|
|
|
+import com.cooleshow.musicmerge.player.CustomPlayer;
|
|
|
|
+import com.cooleshow.musicmerge.presenter.MusicFileHandlePresenter;
|
|
|
|
+import com.cooleshow.musicmerge.viewmodel.MusicMergeViewModel;
|
|
|
|
+import com.luck.picture.lib.PictureSelector;
|
|
|
|
+import com.luck.picture.lib.entity.LocalMedia;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Locale;
|
|
|
|
+
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
|
+import androidx.annotation.Nullable;
|
|
|
|
+import androidx.lifecycle.ViewModelProvider;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Author by pq, Date on 2023/8/28.
|
|
|
|
+ */
|
|
|
|
+@Route(path = RouterPath.MusicTuner.MUSIC_MERGE_PAGE)
|
|
|
|
+public class MusicHandleActivity extends BaseMVPActivity<AcMusicHandleLayoutBinding, MusicFileHandlePresenter> implements View.OnClickListener, SurfaceHolder.Callback, MusicFileHandleContract {
|
|
|
|
+ public static final int REQUEST_CODE_LOCAL = 0x19;
|
|
|
|
+ private CustomPlayer player1;
|
|
|
|
+ private CustomPlayer player2;
|
|
|
|
+ private String accompanyUrl;
|
|
|
|
+ private String recordFilePath;
|
|
|
|
+ private MusicHandleSettingFragment mSettingFragment;
|
|
|
|
+ private boolean isVideo;
|
|
|
|
+ private SurfaceView mSurfaceView;
|
|
|
|
+ private int videoWidth;
|
|
|
|
+ private int videoHeight;
|
|
|
|
+ private Handler mHandler = new Handler(Looper.getMainLooper());
|
|
|
|
+ private String mRecordId;
|
|
|
|
+ private String worksId;
|
|
|
|
+ private String imgCover;
|
|
|
|
+ private String des;
|
|
|
|
+ private ObjectAnimator mRotateAnimation;
|
|
|
|
+ private ObjectAnimator mAlbumRotationAnimator;
|
|
|
|
+ private String originalFileUrl = "";
|
|
|
|
+ private String mTitle;
|
|
|
|
+ private MusicMergeViewModel mViewModel;
|
|
|
|
+
|
|
|
|
+ private boolean isNeedFinishPage = false;
|
|
|
|
+
|
|
|
|
+ private boolean isNeedResetScreenOrientation = true;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
+ QMUIStatusBarHelper.hideStatusBar(this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void initView() {
|
|
|
|
+ mTitle = getIntent().getStringExtra("title");
|
|
|
|
+ viewBinding.tvTitle.setText(mTitle);
|
|
|
|
+ int c_orientation = getIntent().getIntExtra("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
|
+ isNeedResetScreenOrientation = c_orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initFragment() {
|
|
|
|
+ mSettingFragment = new MusicHandleSettingFragment();
|
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
|
+ bundle.putString("accompanyUrl", accompanyUrl);
|
|
|
|
+ mSettingFragment.setArguments(bundle);
|
|
|
|
+ getSupportFragmentManager().beginTransaction().replace(R.id.fl_setting, mSettingFragment).commitAllowingStateLoss();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initSurfaceView() {
|
|
|
|
+ initVideoUIStyle();
|
|
|
|
+ viewBinding.groupAudioView.setVisibility(View.GONE);
|
|
|
|
+ viewBinding.flSurface.setVisibility(View.VISIBLE);
|
|
|
|
+ viewBinding.viewVideoTopBg.setVisibility(View.VISIBLE);
|
|
|
|
+ viewBinding.viewVideoBottomBg.setVisibility(View.VISIBLE);
|
|
|
|
+ viewBinding.viewVideoBg.setVisibility(View.VISIBLE);
|
|
|
|
+ mSurfaceView = new SurfaceView(MusicHandleActivity.this);
|
|
|
|
+ SurfaceHolder holder = mSurfaceView.getHolder();
|
|
|
|
+ FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
|
|
|
|
+ layoutParams.gravity = Gravity.CENTER;
|
|
|
|
+ viewBinding.flSurface.addView(mSurfaceView, layoutParams);
|
|
|
|
+ holder.addCallback(MusicHandleActivity.this);
|
|
|
|
+ holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initVideoUIStyle() {
|
|
|
|
+ viewBinding.tvTitle.setTextColor(Color.WHITE);
|
|
|
|
+ viewBinding.ivBack.setImageResource(com.cooleshow.base.R.drawable.ic_back_white);
|
|
|
|
+ viewBinding.ivPlay.setImageResource(R.drawable.icon_music_merge_play_white);
|
|
|
|
+ viewBinding.tvCurrentProgress.setTextColor(Color.WHITE);
|
|
|
|
+ viewBinding.tvTotalProgress.setTextColor(Color.WHITE);
|
|
|
|
+ viewBinding.seekPlay.setThumb(getResources().getDrawable(R.drawable.shape_volume_progreesbar_thumb2));
|
|
|
|
+ setSeekBarProgressDrawable(viewBinding.seekPlay, getResources().getDrawable(R.drawable.shape_play_progress_seekbar_bg2));
|
|
|
|
+
|
|
|
|
+ viewBinding.tvTotalProgress2.setTextColor(Color.WHITE);
|
|
|
|
+ viewBinding.seekPlay2.setThumb(getResources().getDrawable(R.drawable.shape_volume_progreesbar_thumb2));
|
|
|
|
+ viewBinding.tvCurrentProgress2.setTextColor(Color.WHITE);
|
|
|
|
+ setSeekBarProgressDrawable(viewBinding.seekPlay2, getResources().getDrawable(R.drawable.shape_play_progress_seekbar_bg2));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setSeekBarProgressDrawable(SeekBar seekBarProgress, Drawable drawable) {
|
|
|
|
+ Rect bounds = seekBarProgress.getProgressDrawable().getBounds();
|
|
|
|
+ seekBarProgress.setProgressDrawable(drawable);
|
|
|
|
+ seekBarProgress.getProgressDrawable().setBounds(bounds);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void initData() {
|
|
|
|
+ super.initData();
|
|
|
|
+ mRecordId = getIntent().getStringExtra("recordId");
|
|
|
|
+ worksId = getIntent().getStringExtra("worksId");
|
|
|
|
+ imgCover = getIntent().getStringExtra("coverImg");
|
|
|
|
+
|
|
|
|
+ loadCover();
|
|
|
|
+ if (TextUtils.isEmpty(mRecordId)) {
|
|
|
|
+ ToastUtil.getInstance().showShort("作品生成失败");
|
|
|
|
+ finish();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ accompanyUrl = getIntent().getStringExtra("accompanyUrl");
|
|
|
|
+ recordFilePath = getIntent().getStringExtra("recordFilePath");
|
|
|
|
+
|
|
|
|
+ initViewModel();
|
|
|
|
+ initFragment();
|
|
|
|
+ initListener();
|
|
|
|
+ initPlayer();
|
|
|
|
+ LOG.i("recordFilePath:" + recordFilePath);
|
|
|
|
+ LOG.i("accompanyUrl:" + accompanyUrl);
|
|
|
|
+ if (!checkRecordFile()) {
|
|
|
|
+ if (!TextUtils.isEmpty(worksId)) {
|
|
|
|
+ presenter.getDetail(worksId);
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("作品生成失败");
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ preLoad();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initViewModel() {
|
|
|
|
+ ViewModelProvider.AndroidViewModelFactory instance =
|
|
|
|
+ ViewModelProvider.AndroidViewModelFactory
|
|
|
|
+ .getInstance(getApplication());
|
|
|
|
+ mViewModel = new ViewModelProvider(this, instance)
|
|
|
|
+ .get(MusicMergeViewModel.class);
|
|
|
|
+ mViewModel.getWorksId().setValue(worksId);
|
|
|
|
+ refreshMusicInfo(imgCover);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void preLoad() {
|
|
|
|
+ isVideo = MyFileUtils.isVideo(recordFilePath);
|
|
|
|
+ LOG.i("isVideo:" + isVideo);
|
|
|
|
+ boolean b = checkAccompanimentMp3File();
|
|
|
|
+ if (b) {
|
|
|
|
+ preparePlay();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void preparePlay() {
|
|
|
|
+ if (isVideo) {
|
|
|
|
+ initSurfaceView();
|
|
|
|
+ } else {
|
|
|
|
+ toPlay(getAccompanyPath());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void loadCover() {
|
|
|
|
+ GlideUtils.INSTANCE.loadImage(this, imgCover, viewBinding.ivCover, R.drawable.icon_default_music_song_cover);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected MusicFileHandlePresenter createPresenter() {
|
|
|
|
+ return new MusicFileHandlePresenter();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initListener() {
|
|
|
|
+ viewBinding.ivBack.setOnClickListener(this);
|
|
|
|
+ viewBinding.ivPlay.setOnClickListener(this);
|
|
|
|
+ viewBinding.ivUnfoldSentting.setOnClickListener(this);
|
|
|
|
+
|
|
|
|
+ mSettingFragment.setEventListener(new MusicHandleSettingFragment.OnEventListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onVolumeChange(int type, float value) {
|
|
|
|
+ if (type == MusicHandleSettingFragment.RECORD_TYPE) {
|
|
|
|
+ player1.setVolume(value);
|
|
|
|
+ } else {
|
|
|
|
+ player2.setVolume(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onOffsetValueChange(int value) {
|
|
|
|
+ aligningAccompany(value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void toMix(int offsetValue, float volume1, float volume2, boolean isNeedNotify) {
|
|
|
|
+ if (isVideo) {
|
|
|
|
+ startMixForMp4(getAccompanyPath(), recordFilePath, offsetValue, volume1, volume2, isNeedNotify);
|
|
|
|
+ } else {
|
|
|
|
+ startMix(getAccompanyPath(), recordFilePath, offsetValue, volume1, volume2, isNeedNotify);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void hideSetting() {
|
|
|
|
+ handleSettingVisibility();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveDraft() {
|
|
|
|
+ //上传原始视频 以及 相关调节参数
|
|
|
|
+ toSaveDraft();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ viewBinding.seekPlay.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
|
|
+ if (fromUser) {
|
|
|
|
+ handleSeekEvent();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onStartTrackingTouch(SeekBar seekBar) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void toSaveDraft() {
|
|
|
|
+ if (!TextUtils.isEmpty(recordFilePath)) {
|
|
|
|
+ if (!TextUtils.isEmpty(originalFileUrl)) {
|
|
|
|
+ toNotifyDraft(originalFileUrl);
|
|
|
|
+ } else {
|
|
|
|
+ uploadDraft(recordFilePath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void uploadDraft(String filePath) {
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ setLoadingCancelable(false);
|
|
|
|
+ showLoading("正在上传草稿0%");
|
|
|
|
+ UploadHelper uploadHelper = new UploadHelper(null, UploadConstants.UPLOAD_TYPE_HOMEWORK);
|
|
|
|
+ uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
|
|
|
|
+ @Override
|
|
|
|
+ protected void onSuccess(String url) {
|
|
|
|
+ updateLoadingText("正在上传草稿100%");
|
|
|
|
+ toNotifyDraft(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void onFailure() {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ hideLoading();
|
|
|
|
+ ToastUtil.getInstance().showShort("草稿上传失败,请重试");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onUploadProgress(double v) {
|
|
|
|
+ Log.i("pq","onUploadProgress"+v);
|
|
|
|
+ updateLoadingText("正在上传草稿"+UiUtils.convertDouble(v)+"%");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ uploadHelper.setLoadingTip("正在上传草稿");
|
|
|
|
+
|
|
|
|
+ uploadHelper.uploadFile(file);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void upload(String filePath) {
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ updateLoadingText("正在上传作品0%");
|
|
|
|
+ UploadHelper uploadHelper = new UploadHelper(null, UploadConstants.UPLOAD_TYPE_HOMEWORK);
|
|
|
|
+ uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
|
|
|
|
+ @Override
|
|
|
|
+ protected void onSuccess(String url) {
|
|
|
|
+ updateLoadingText("正在上传作品100%");
|
|
|
|
+ toNotify(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void onFailure() {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ hideLoading();
|
|
|
|
+ ToastUtil.getInstance().showShort("作品上传失败,请重试");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onUploadProgress(double v) {
|
|
|
|
+ updateLoadingText("正在上传作品"+ UiUtils.convertDouble(v)+"%");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ uploadHelper.setLoadingTip("正在上传作品");
|
|
|
|
+
|
|
|
|
+ uploadHelper.uploadFile(file);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void toNotify(String url) {
|
|
|
|
+ String configJson = mSettingFragment.getConfigJson();
|
|
|
|
+ MusicInfoBean value = mViewModel.getMusicInfoLiveData().getValue();
|
|
|
|
+ String cover = imgCover;
|
|
|
|
+ if (value != null) {
|
|
|
|
+ String preCover = value.getPreCover();
|
|
|
|
+ if (!TextUtils.isEmpty(preCover)) {
|
|
|
|
+ cover = preCover;
|
|
|
|
+ }
|
|
|
|
+ des = value.getDes();
|
|
|
|
+ }
|
|
|
|
+ presenter.save(mRecordId, url, cover, des, configJson);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void toNotifyDraft(String url) {
|
|
|
|
+ if (mSettingFragment != null) {
|
|
|
|
+ String configJson = mSettingFragment.getConfigJson();
|
|
|
|
+ presenter.saveDraft(mRecordId, url, accompanyUrl, imgCover, configJson);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void startMixForMp4(String accompanimentMp3Path, String recordFilePath, int offsetValue, float recordFileVolume, float accompanyFileVolume, boolean isNeedNotify) {
|
|
|
|
+ setLoadingCancelable(false);
|
|
|
|
+ showLoading(String.format(Locale.getDefault(), "视频合成中 %d%%", 0));
|
|
|
|
+ MixHelper.getInstance().startMixForMp4(accompanimentMp3Path, recordFilePath, offsetValue, recordFileVolume, accompanyFileVolume, new ResultCallback<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(String s) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ updateLoadingText(String.format(Locale.getDefault(), "视频合成中 %d%%", 100));
|
|
|
|
+ if (!TextUtils.isEmpty(s)) {
|
|
|
|
+// ToastUtil.getInstance().showShort("mix completed:" + s);
|
|
|
|
+ FileUtils.notifySystemToScan(s);
|
|
|
|
+ if (isNeedNotify) {
|
|
|
|
+ upload(s);
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("保存成功");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("mix onFail");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progressPercent) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ LOG.i("progressPercent:" + progressPercent);
|
|
|
|
+ updateLoadingText(String.format(Locale.getDefault(), "视频合成中 %d%%", progressPercent));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFail(int errorCode, String errorStr) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ hideLoading();
|
|
|
|
+ ToastUtil.getInstance().showShort("mix onFail:" + errorCode + "--reason:" + errorStr);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void startMix(String accompanimentMp3Path, String recordFilePath, int offsetValue, float recordFileVolume, float accompanyFileVolume, boolean isNeedNotify) {
|
|
|
|
+ setLoadingCancelable(false);
|
|
|
|
+ showLoading(String.format(Locale.getDefault(), "音频合成中 %d%%", 0));
|
|
|
|
+ MixHelper.getInstance().startMix(accompanimentMp3Path, recordFilePath, offsetValue, recordFileVolume, accompanyFileVolume, new ResultCallback<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(String s) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ updateLoadingText(String.format(Locale.getDefault(), "音频合成中 %d%%", 100));
|
|
|
|
+ hideLoading();
|
|
|
|
+// ToastUtil.getInstance().showShort("mix completed:" + s);
|
|
|
|
+ if (!TextUtils.isEmpty(s)) {
|
|
|
|
+ FileUtils.notifySystemToScan(s);
|
|
|
|
+ if (isNeedNotify) {
|
|
|
|
+ upload(s);
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("保存成功");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("mix onFail");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progressPercent) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ LOG.i("progressPercent:" + progressPercent);
|
|
|
|
+ updateLoadingText(String.format(Locale.getDefault(), "音频合成中 %d%%", progressPercent));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFail(int errorCode, String errorStr) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ hideLoading();
|
|
|
|
+ ToastUtil.getInstance().showShort("mix onFail:" + errorCode + "--reason:" + errorStr);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void aligningAccompany(int value) {
|
|
|
|
+ int cu = player1.getCu();
|
|
|
|
+ LOG.i("pq", "cu:" + cu);
|
|
|
|
+ LOG.i("pq", "currentOffsetValue:" + value);
|
|
|
|
+ int seekResult2 = cu - value;
|
|
|
|
+ LOG.i("pq", "seekResult2:" + seekResult2);
|
|
|
|
+ player2.seekTo(seekResult2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void handleSeekEvent() {
|
|
|
|
+ int progress = viewBinding.seekPlay.getProgress();
|
|
|
|
+ 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;
|
|
|
|
+ LOG.i("pq", "seekResult2:" + seekResult2);
|
|
|
|
+ player1.seekTo(seekResult);
|
|
|
|
+ player2.seekTo(seekResult2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initPlayer() {
|
|
|
|
+ player1 = new CustomPlayer("luzhi");
|
|
|
|
+ player2 = new CustomPlayer("伴奏");
|
|
|
|
+ player1.setOnEventListener(new CustomPlayer.OnEventListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progress) {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String s = TimeUtils.msToTime(progress);
|
|
|
|
+ viewBinding.tvCurrentProgress.setText(s);
|
|
|
|
+ int maxProgress = viewBinding.seekPlay.getMax();
|
|
|
|
+ int percent = (int) ((progress * 1.0f / player1.getTotal()) * maxProgress);
|
|
|
|
+ viewBinding.seekPlay.setProgress(percent);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onPrepared(int duration) {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String s = TimeUtils.msToTime(duration);
|
|
|
|
+ viewBinding.tvTotalProgress.setText(s);
|
|
|
|
+ setVolume();
|
|
|
|
+ updatePlayStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onCompleted() {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ viewBinding.seekPlay.setProgress(0);
|
|
|
|
+ viewBinding.seekPlay2.setProgress(0);
|
|
|
|
+ player2.pause();
|
|
|
|
+ handleSeekEvent();
|
|
|
|
+ updatePlayStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
|
|
|
|
+ MusicHandleActivity.this.videoWidth = width;
|
|
|
|
+ MusicHandleActivity.this.videoHeight = height;
|
|
|
|
+ resetVideoSize(width, height);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ player2.setOnEventListener(new CustomPlayer.OnEventListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progress) {
|
|
|
|
+ String s = TimeUtils.msToTime(progress);
|
|
|
|
+ viewBinding.tvCurrentProgress2.setText(s);
|
|
|
|
+ int maxProgress = viewBinding.seekPlay2.getMax();
|
|
|
|
+ int percent = (int) ((progress * 1.0f / player2.getTotal()) * maxProgress);
|
|
|
|
+ viewBinding.seekPlay2.setProgress(percent);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onPrepared(int duration) {
|
|
|
|
+ String s = TimeUtils.msToTime(duration);
|
|
|
|
+ viewBinding.tvTotalProgress2.setText(s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onCompleted() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setVolume() {
|
|
|
|
+ if (mSettingFragment != null) {
|
|
|
|
+ int originalVolume = mSettingFragment.getOriginalVolume();
|
|
|
|
+ int accompanyVolume = mSettingFragment.getAccompanyVolume();
|
|
|
|
+ player1.setVolume(originalVolume);
|
|
|
|
+ player2.setVolume(accompanyVolume);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void resetVideoSize(int width, int height) {
|
|
|
|
+ int surfaceWidth = viewBinding.flSurface.getWidth();
|
|
|
|
+ int surfaceHeight = viewBinding.flSurface.getHeight();
|
|
|
|
+ LOG.i("pq", "surfaceWidth:" + surfaceWidth);
|
|
|
|
+ LOG.i("pq", "surfaceHeight:" + surfaceHeight);
|
|
|
|
+ float percent = surfaceWidth * 1.0f / surfaceHeight;
|
|
|
|
+ float percent2 = width * 1.0f / height;
|
|
|
|
+ LOG.i("pq", "percent:" + percent);
|
|
|
|
+ LOG.i("pq", "percent2:" + percent2);
|
|
|
|
+ boolean b = NumberUtils.compareResult(percent, percent2);
|
|
|
|
+ LOG.i("pq", "compareResult:" + b);
|
|
|
|
+ if (b) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ LOG.i("pq", "videoWidth:" + width);
|
|
|
|
+ LOG.i("pq", "videoHeight:" + height);
|
|
|
|
+ int w = surfaceWidth;
|
|
|
|
+ int h = (int) ((surfaceWidth * 1.0f / width) * height);
|
|
|
|
+ LOG.i("pq", "w:" + w);
|
|
|
|
+ LOG.i("pq", "h:" + h);
|
|
|
|
+ if (w > surfaceWidth) {
|
|
|
|
+ w = surfaceWidth;
|
|
|
|
+ }
|
|
|
|
+ if (h > surfaceHeight) {
|
|
|
|
+ h = surfaceHeight;
|
|
|
|
+ }
|
|
|
|
+ LOG.i("pq", "w:" + w);
|
|
|
|
+ LOG.i("pq", "h:" + h);
|
|
|
|
+ FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mSurfaceView.getLayoutParams();
|
|
|
|
+ layoutParams.width = w;
|
|
|
|
+ layoutParams.height = h;
|
|
|
|
+ mSurfaceView.setLayoutParams(layoutParams);
|
|
|
|
+ mSurfaceView.getHolder().setFixedSize(w, h);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean checkRecordFile() {
|
|
|
|
+ if (TextUtils.isEmpty(recordFilePath)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ File file = new File(recordFilePath);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void toPlay(String accompanyPath) {
|
|
|
|
+ player1.play(recordFilePath);
|
|
|
|
+ player2.play(accompanyPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean checkRecordFile(String recordUrl) {
|
|
|
|
+ String fileEndSuffix = MyFileUtils.getWAVOrMp4FileSuffix(recordUrl);
|
|
|
|
+ String recordFileDownloadPath = getRecordFileDownloadPath(recordUrl, fileEndSuffix);
|
|
|
|
+ recordFilePath = recordFileDownloadPath;
|
|
|
|
+ Log.i("pq", "checkRecordFile:" + recordFilePath);
|
|
|
|
+ File file = new File(recordFileDownloadPath);
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ Log.i("pq", "下载草稿");
|
|
|
|
+ setLoadingCancelable(false);
|
|
|
|
+ showLoading("草稿下载中");
|
|
|
|
+ MixHelper.getInstance().download(recordUrl, fileEndSuffix, new ResultCallback<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(String s) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ hideLoading();
|
|
|
|
+ preLoad();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progressPercent) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ updateLoadingText("草稿下载中" + progressPercent + "%");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFail(int errorCode, String errorStr) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ ToastUtil.getInstance().showShort("草稿下载失败,请重试");
|
|
|
|
+ hideLoading();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean checkAccompanimentMp3File() {
|
|
|
|
+ if (TextUtils.isEmpty(accompanyUrl)) {
|
|
|
|
+ ToastUtil.getInstance().showShort("未找到伴奏文件,请退出重试");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ String accompanyPath = getAccompanyPath();
|
|
|
|
+ File file = new File(accompanyPath);
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ setLoadingCancelable(false);
|
|
|
|
+ showLoading("伴奏下载中");
|
|
|
|
+ MixHelper.getInstance().download(accompanyUrl, MyFileUtils.MP3_FILE_SUFFIX, new ResultCallback<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(String s) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ preparePlay();
|
|
|
|
+ hideLoading();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onProgress(int progressPercent) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ updateLoadingText("伴奏下载中" + progressPercent + "%");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFail(int errorCode, String errorStr) {
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ ToastUtil.getInstance().showShort("伴奏下载失败,请重试");
|
|
|
|
+ hideLoading();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void hideLoading() {
|
|
|
|
+ setLoadingCancelable(true);
|
|
|
|
+ super.hideLoading();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getAccompanyPath() {
|
|
|
|
+ String accompanyPath = MixHelper.getInstance().getDownloadSavePath(accompanyUrl);
|
|
|
|
+ return accompanyPath;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getRecordFileDownloadPath(String recordFileUrl, String fileEndSuffix) {
|
|
|
|
+ String recordFilePath;
|
|
|
|
+ if (MyFileUtils.isVideoFromUrl(recordFileUrl)) {
|
|
|
|
+ recordFilePath = MixHelper.getInstance().getDownloadSavePathForMp4(recordFileUrl);
|
|
|
|
+ } else {
|
|
|
|
+ recordFilePath = MixHelper.getInstance().getDownloadSavePath(recordFileUrl, fileEndSuffix);
|
|
|
|
+ }
|
|
|
|
+ return recordFilePath;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected AcMusicHandleLayoutBinding getLayoutView() {
|
|
|
|
+ return AcMusicHandleLayoutBinding.inflate(getLayoutInflater());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ int id = v.getId();
|
|
|
|
+ if (id == R.id.iv_play) {
|
|
|
|
+ if (player1.isPlaying()) {
|
|
|
|
+ player1.pause();
|
|
|
|
+ player2.pause();
|
|
|
|
+ } else {
|
|
|
|
+ player1.resume();
|
|
|
|
+ player2.resume();
|
|
|
|
+ }
|
|
|
|
+ updatePlayStatus();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (id == R.id.iv_unfold_sentting) {
|
|
|
|
+ handleSettingVisibility();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (id == R.id.iv_back) {
|
|
|
|
+ checkTipToFinish();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void onStop() {
|
|
|
|
+ super.onStop();
|
|
|
|
+ pausePlay();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void pausePlay() {
|
|
|
|
+ if (player1.isPlaying()) {
|
|
|
|
+ player1.pause();
|
|
|
|
+ player2.pause();
|
|
|
|
+ }
|
|
|
|
+ updatePlayStatus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkTipToFinish() {
|
|
|
|
+ boolean hasUpdate = mViewModel.isHasUpdate();
|
|
|
|
+ if (hasUpdate) {
|
|
|
|
+ showSaveTipDialog();
|
|
|
|
+ } else {
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void showSaveTipDialog() {
|
|
|
|
+ CommonConfirmDialog2 commonConfirmDialog = new CommonConfirmDialog2(this);
|
|
|
|
+ commonConfirmDialog.setWidth(SizeUtils.dp2px(387));
|
|
|
|
+ commonConfirmDialog.show();
|
|
|
|
+ commonConfirmDialog.setTitle("提示");
|
|
|
|
+ commonConfirmDialog.setContent("是否将本次录制的作品保存为草稿?");
|
|
|
|
+ commonConfirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
|
+ isNeedFinishPage = true;
|
|
|
|
+ toSaveDraft();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ commonConfirmDialog.setOnCancelClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 监听返回键
|
|
|
|
+ *
|
|
|
|
+ * @param keyCode
|
|
|
|
+ * @param event
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
+ checkTipToFinish();
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void handleSettingVisibility() {
|
|
|
|
+ int visibility = viewBinding.flSetting.getVisibility();
|
|
|
|
+ if (visibility == View.VISIBLE) {
|
|
|
|
+ viewBinding.groupSetting.setVisibility(View.GONE);
|
|
|
|
+ viewBinding.ivUnfoldSentting.setVisibility(View.VISIBLE);
|
|
|
|
+ } else {
|
|
|
|
+ viewBinding.groupSetting.setVisibility(View.VISIBLE);
|
|
|
|
+ viewBinding.ivUnfoldSentting.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ resetVideoSize(videoWidth, videoHeight);
|
|
|
|
+ }
|
|
|
|
+ }, 50);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updatePlayStatus() {
|
|
|
|
+ if (player1.isPlaying()) {
|
|
|
|
+ viewBinding.ivPlayPointer.setRotation(0);
|
|
|
|
+ handleAnim(true);
|
|
|
|
+ viewBinding.ivPlay.setImageResource(isVideo ? R.drawable.icon_music_merge_pause_white : R.drawable.icon_music_merge_pause);
|
|
|
|
+ } else {
|
|
|
|
+ handleAnim(false);
|
|
|
|
+ viewBinding.ivPlayPointer.setRotation(92);
|
|
|
|
+ viewBinding.ivPlay.setImageResource(isVideo ? R.drawable.icon_music_merge_play_white : R.drawable.icon_music_merge_play);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void handleAnim(boolean isPlay) {
|
|
|
|
+ if (isVideo) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (player1 != null && player1.getPlayer() != null && isPlay) {
|
|
|
|
+ viewBinding.musicFrequencyView.setMediaPlayer(player1.getPlayer());
|
|
|
|
+ }
|
|
|
|
+ rotation(isPlay);
|
|
|
|
+ rotationAlbum(isPlay);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void rotation(boolean isPlay) {
|
|
|
|
+ float from = isPlay ? 92 : 0;
|
|
|
|
+ float to = isPlay ? 0 : 92;
|
|
|
|
+ viewBinding.ivPlayPointer.clearAnimation();
|
|
|
|
+ float rotation = viewBinding.ivPlayPointer.getRotation();
|
|
|
|
+ LOG.i("rotation:" + rotation);
|
|
|
|
+ if (mRotateAnimation == null) {
|
|
|
|
+ mRotateAnimation = ObjectAnimator.ofFloat(viewBinding.ivPlayPointer, "rotation", from, to);
|
|
|
|
+ mRotateAnimation.setInterpolator(new LinearInterpolator());//不停顿
|
|
|
|
+ mRotateAnimation.setDuration(300);
|
|
|
|
+ mRotateAnimation.setRepeatCount(0);
|
|
|
|
+ }
|
|
|
|
+ mRotateAnimation.setFloatValues(from, to);
|
|
|
|
+ mRotateAnimation.start();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void rotationAlbum(boolean isPlay) {
|
|
|
|
+ float rotation = viewBinding.flAblum.getRotation();
|
|
|
|
+ if (mAlbumRotationAnimator == null) {
|
|
|
|
+ mAlbumRotationAnimator = ObjectAnimator.ofFloat(viewBinding.flAblum, "rotation", 0f, 360f);
|
|
|
|
+ mAlbumRotationAnimator.setDuration(5000); // 设置动画持续时间为1秒
|
|
|
|
+ mAlbumRotationAnimator.setRepeatCount(ObjectAnimator.INFINITE); // 设置无限循环
|
|
|
|
+ mAlbumRotationAnimator.setInterpolator(new LinearInterpolator()); // 设置动画插值器,这里使用线性插值器
|
|
|
|
+ }
|
|
|
|
+ if (isPlay) {
|
|
|
|
+ if (mAlbumRotationAnimator.isPaused()) {
|
|
|
|
+ mAlbumRotationAnimator.resume();
|
|
|
|
+ } else {
|
|
|
|
+ mAlbumRotationAnimator.start(); // 启动动画
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ mAlbumRotationAnimator.pause();//
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveWorksSuccess() {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ showToastViewAndFinish("发布成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void toFinish() {
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
+ intent.putExtra("saveWorksStatus", 1);
|
|
|
|
+ setResult(RESULT_OK, intent);
|
|
|
|
+ finish();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getDetailSuccess(MusicDataBean data) {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (data != null) {
|
|
|
|
+ this.originalFileUrl = data.getVideoUrl();
|
|
|
|
+ String jsonConfig = data.getJsonConfig();
|
|
|
|
+ accompanyUrl = data.getAccompanyUrl();
|
|
|
|
+ if (mSettingFragment != null) {
|
|
|
|
+ if (!TextUtils.isEmpty(jsonConfig)) {
|
|
|
|
+ mSettingFragment.applyConfig(jsonConfig);
|
|
|
|
+ }
|
|
|
|
+ mSettingFragment.setAccompanyUrl(accompanyUrl);
|
|
|
|
+ }
|
|
|
|
+ //这里为了兼容IOS录制的wav音频文件格式不正确 导致合成失败的问题Failed to read frame size: Could not seek to 1026.
|
|
|
|
+ //取服务端存储的文件
|
|
|
|
+ boolean isVideo = MyFileUtils.isVideoFromUrl(data.getVideoUrl());
|
|
|
|
+ String fileUrl = isVideo ? data.getVideoUrl() : data.getRecordFilePath();
|
|
|
|
+ boolean b = checkRecordFile(fileUrl);
|
|
|
|
+ if (b) {
|
|
|
|
+ preLoad();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveWorksDraftSuccess() {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ mViewModel.getUpdateEvent().setValue(false);
|
|
|
|
+ if (isNeedFinishPage) {
|
|
|
|
+ showToastViewAndFinish("保存成功");
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("保存成功");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void showToastViewAndFinish(String tip) {
|
|
|
|
+ //测试lyr提出提示要在当前面提示,所以给出延迟finish
|
|
|
|
+ viewBinding.tvToastView.setText(tip);
|
|
|
|
+ viewBinding.tvToastView.setVisibility(View.VISIBLE);
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ toFinish();
|
|
|
|
+ }
|
|
|
|
+ }, 1500);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void upLoadImageSuccess(String url) {
|
|
|
|
+ if (!checkActivityExist()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ refreshMusicInfoPreCover(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void refreshMusicInfoPreCover(String imgCover) {
|
|
|
|
+ mViewModel.refreshMusicPreCover(imgCover);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void refreshMusicInfo(String imgCover) {
|
|
|
|
+ MusicInfoBean bean = new MusicInfoBean();
|
|
|
|
+ bean.setCover(imgCover);
|
|
|
|
+ bean.setMusicTitle(mTitle);
|
|
|
|
+ mViewModel.getMusicInfoLiveData().setValue(bean);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void upLoadImageFailure() {
|
|
|
|
+ ToastUtil.getInstance().showShort("上传失败,请重试");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
|
+ if (requestCode == REQUEST_CODE_LOCAL) {
|
|
|
|
+ if (data != null) {
|
|
|
|
+ // 图片、视频、音频选择结果回调
|
|
|
|
+ List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
|
|
|
|
+ String v_path = null;
|
|
|
|
+ if (selectList != null && selectList.size() > 0) {
|
|
|
|
+ v_path = selectList.get(0).getCompressPath();
|
|
|
|
+ }
|
|
|
|
+ if (!TextUtils.isEmpty(v_path)) {
|
|
|
|
+ boolean isImg = MyFileUtils.isImg(v_path);
|
|
|
|
+ if (isImg) {
|
|
|
|
+ presenter.upLoadImage(MusicHandleActivity.this, v_path);
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().showShort("请选择图片类型文件");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDestroy() {
|
|
|
|
+ releaseAnim();
|
|
|
|
+ super.onDestroy();
|
|
|
|
+ if (mHandler != null) {
|
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (player1 != null) {
|
|
|
|
+ player1.release();
|
|
|
|
+ }
|
|
|
|
+ if (player2 != null) {
|
|
|
|
+ player2.release();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void releaseAnim() {
|
|
|
|
+ if (viewBinding != null && viewBinding.musicFrequencyView != null) {
|
|
|
|
+ viewBinding.musicFrequencyView.release();
|
|
|
|
+ }
|
|
|
|
+ if (mRotateAnimation != null) {
|
|
|
|
+ mRotateAnimation.cancel();
|
|
|
|
+ mRotateAnimation = null;
|
|
|
|
+ }
|
|
|
|
+ if (mAlbumRotationAnimator != null) {
|
|
|
|
+ mAlbumRotationAnimator.cancel();
|
|
|
|
+ mAlbumRotationAnimator = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void surfaceCreated(@NonNull SurfaceHolder holder) {
|
|
|
|
+ LOG.i("surfaceCreated");
|
|
|
|
+ player1.setSurface(holder);
|
|
|
|
+ toPlay(getAccompanyPath());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
|
|
|
|
+ LOG.i("surfaceChanged");
|
|
|
|
+ player1.setSurface(holder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
|
|
|
|
+ LOG.i("surfaceDestroyed");
|
|
|
|
+ if (player1 != null && player1.isPlaying()) {
|
|
|
|
+ pausePlay();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void finish() {
|
|
|
|
+ //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
|
|
|
|
+ //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
|
|
|
|
+ checkScreenOrientation();
|
|
|
|
+ super.finish();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onBackPressed() {
|
|
|
|
+ //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
|
|
|
|
+ //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
|
|
|
|
+ checkScreenOrientation();
|
|
|
|
+ super.onBackPressed();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkScreenOrientation() {
|
|
|
|
+ LOG.i("isNeedResetScreenOrientation:" + isNeedResetScreenOrientation);
|
|
|
|
+ if (isNeedResetScreenOrientation) {
|
|
|
|
+ if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|