Commit 3286cfc636bfd52c658fbed46f68a97f4f179309
1 parent
b8684977
1.优化视频拍摄页面重新构建逻辑
Showing
4 changed files
with
59 additions
and
22 deletions
lib_media/src/main/java/com/cnlive/media/frame/view/RecordFragmentView.java
| ... | ... | @@ -62,8 +62,8 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { |
| 62 | 62 | |
| 63 | 63 | Log.e("启动流程","initView"); |
| 64 | 64 | if (getActivity().mOptions == null) { |
| 65 | - showMesage("数据异常"); | |
| 66 | - mFragment.getActivity().finish(); | |
| 65 | + //Activity 缓存数据失效,一般情况是App被系统回收 | |
| 66 | + return; | |
| 67 | 67 | } |
| 68 | 68 | // 摄像头采集选项 |
| 69 | 69 | if (mFragment.plShortVideoRecorder == null) | ... | ... |
lib_media/src/main/java/com/cnlive/media/frame/view/RecordView.java
| ... | ... | @@ -69,11 +69,13 @@ public class RecordView implements MvpView { |
| 69 | 69 | hasPermissions = mActivity.getPresenter().checkPermissions(mActivity, mActivity.permissionsRecordNoAudio, mActivity.PERMISISSION_CODE_ASK, true); |
| 70 | 70 | } |
| 71 | 71 | if (hasPermissions) { |
| 72 | - if ( mActivity.getSupportFragmentManager().getFragments()==null|| mActivity.getSupportFragmentManager().getFragments().size()==0){ | |
| 73 | - mActivity.isInit=true; | |
| 74 | - mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.pre_frame, RecordFragment.newInstance()).addToBackStack("").commit(); | |
| 72 | + mActivity.isInit = true; | |
| 73 | + mActivity.getSupportFragmentManager() | |
| 74 | + .beginTransaction() | |
| 75 | + .replace(R.id.pre_frame, RecordFragment.newInstance()) | |
| 76 | + .addToBackStack("") | |
| 77 | + .commit(); | |
| 75 | 78 | |
| 76 | - } | |
| 77 | 79 | } |
| 78 | 80 | |
| 79 | 81 | } | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/activity/RecordActivity.java
| ... | ... | @@ -116,18 +116,15 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent |
| 116 | 116 | }); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - | |
| 120 | 119 | @Override |
| 121 | - public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) { | |
| 122 | - super.onSaveInstanceState(outState, outPersistentState); | |
| 123 | - if (outState != null) { | |
| 124 | - if (mOptions != null) outState.putParcelable(PickerConfig.INTENT_KEY_OPTIONS, mOptions); | |
| 125 | - outState.putInt(PickerConfig.RESULT_CODE, resultCode); | |
| 126 | - outState.putBoolean(PickerConfig.WHERE_JUMP_CAMERA, isJumpCamera); | |
| 127 | - if (selectMedia != null) | |
| 128 | - outState.putParcelableArrayList(PickerConfig.WHERE_JUMP_CAMERA_SELECTS, selectMedia); | |
| 129 | - } | |
| 130 | - | |
| 120 | + protected void onSaveInstanceState(Bundle outState) { | |
| 121 | + Log.e("DemoView", "缓存 " + mOptions); | |
| 122 | + if (mOptions != null) outState.putParcelable(PickerConfig.INTENT_KEY_OPTIONS, mOptions); | |
| 123 | + outState.putInt(PickerConfig.RESULT_CODE, resultCode); | |
| 124 | + outState.putBoolean(PickerConfig.WHERE_JUMP_CAMERA, isJumpCamera); | |
| 125 | + if (selectMedia != null) | |
| 126 | + outState.putParcelableArrayList(PickerConfig.WHERE_JUMP_CAMERA_SELECTS, selectMedia); | |
| 127 | + super.onSaveInstanceState(outState); | |
| 131 | 128 | } |
| 132 | 129 | |
| 133 | 130 | public void showPreViewImg(Bitmap plbitMap) { | ... | ... |
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordFragment.java
| 1 | 1 | package com.cnlive.media.ui.fragment; |
| 2 | 2 | |
| 3 | +import android.Manifest; | |
| 4 | +import android.content.pm.PackageManager; | |
| 3 | 5 | import android.graphics.Bitmap; |
| 4 | 6 | import android.os.Bundle; |
| 5 | 7 | import android.text.TextUtils; |
| ... | ... | @@ -8,6 +10,7 @@ import android.view.View; |
| 8 | 10 | |
| 9 | 11 | import androidx.activity.OnBackPressedCallback; |
| 10 | 12 | import androidx.annotation.Nullable; |
| 13 | +import androidx.core.app.ActivityCompat; | |
| 11 | 14 | |
| 12 | 15 | import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; |
| 13 | 16 | import com.cnlive.libs.base.util.DoublePressed; |
| ... | ... | @@ -62,14 +65,41 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor |
| 62 | 65 | //录制中 |
| 63 | 66 | public boolean isRecordIng; |
| 64 | 67 | |
| 68 | + public boolean permission = false; | |
| 69 | + | |
| 65 | 70 | @Override |
| 66 | 71 | protected int getLayoutId() { |
| 67 | 72 | return R.layout.fragment_record; |
| 68 | 73 | } |
| 69 | 74 | |
| 75 | + private boolean checkPermission() { | |
| 76 | + if (getActivity() == null) return false; | |
| 77 | + | |
| 78 | + boolean hasPermisson = true; | |
| 79 | + | |
| 80 | + for (String permisson : new String[]{ | |
| 81 | + Manifest.permission.CAMERA, | |
| 82 | + Manifest.permission.RECORD_AUDIO, | |
| 83 | + Manifest.permission.READ_EXTERNAL_STORAGE, | |
| 84 | + Manifest.permission.WRITE_EXTERNAL_STORAGE}) { | |
| 85 | + if (ActivityCompat.checkSelfPermission(getActivity(), permisson) != PackageManager.PERMISSION_GRANTED) { | |
| 86 | + hasPermisson = false; | |
| 87 | + break; | |
| 88 | + } | |
| 89 | + } | |
| 90 | + return hasPermisson; | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void onCreate(Bundle savedInstanceState) { | |
| 95 | + super.onCreate(savedInstanceState); | |
| 96 | + permission = checkPermission(); | |
| 97 | + } | |
| 98 | + | |
| 70 | 99 | @Override |
| 71 | 100 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 72 | 101 | super.onViewCreated(view, savedInstanceState); |
| 102 | + if (!permission) return; | |
| 73 | 103 | RecordCameraViewObservable.newInstance().addObserver(this); |
| 74 | 104 | Log.e("启动流程:","onViewCreated"+savedInstanceState); |
| 75 | 105 | if (getMvpView() != null) getMvpView().initView(); |
| ... | ... | @@ -84,16 +114,21 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor |
| 84 | 114 | @Override |
| 85 | 115 | public void onResume() { |
| 86 | 116 | super.onResume(); |
| 117 | + if (!permission) return; | |
| 118 | + | |
| 87 | 119 | Log.e("启动流程:","FragmentonResume"); |
| 88 | 120 | if (isFlash && getMvpView() != null) getMvpView().processFlash(isFlash); |
| 89 | - if (plShortVideoRecorder != null) plShortVideoRecorder.resume(); | |
| 90 | - plShortVideoRecorder.deleteLastSection(); | |
| 91 | - | |
| 121 | + if (plShortVideoRecorder != null) { | |
| 122 | + plShortVideoRecorder.resume(); | |
| 123 | + plShortVideoRecorder.deleteLastSection(); | |
| 124 | + } | |
| 92 | 125 | } |
| 93 | 126 | |
| 94 | 127 | @Override |
| 95 | 128 | public void onPause() { |
| 96 | 129 | super.onPause(); |
| 130 | + if (!permission) return; | |
| 131 | + | |
| 97 | 132 | isRecordIng = false; |
| 98 | 133 | if (plShortVideoRecorder != null) { |
| 99 | 134 | binding.rcControl.resetRecord(); |
| ... | ... | @@ -104,9 +139,12 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor |
| 104 | 139 | @Override |
| 105 | 140 | public void onDestroy() { |
| 106 | 141 | super.onDestroy(); |
| 107 | - RecordCameraViewObservable.newInstance().deleteObserver(this); | |
| 108 | - if (plShortVideoRecorder != null) plShortVideoRecorder.destroy(); | |
| 142 | + if (!permission) return; | |
| 109 | 143 | |
| 144 | + RecordCameraViewObservable.newInstance().deleteObserver(this); | |
| 145 | + if (plShortVideoRecorder != null) { | |
| 146 | + plShortVideoRecorder.destroy(); | |
| 147 | + } | |
| 110 | 148 | } |
| 111 | 149 | |
| 112 | 150 | ... | ... |