Commit 98e9df58b52854463474af40168b2441c0cff89e
1 parent
ec44c48e
BUG修改
Showing
18 changed files
with
375 additions
and
88 deletions
app/src/main/java/com/cnlive/strike/debug/MainActivity.java
| @@ -5,16 +5,20 @@ import androidx.appcompat.app.AppCompatActivity; | @@ -5,16 +5,20 @@ import androidx.appcompat.app.AppCompatActivity; | ||
| 5 | import androidx.databinding.DataBindingUtil; | 5 | import androidx.databinding.DataBindingUtil; |
| 6 | 6 | ||
| 7 | import android.content.Intent; | 7 | import android.content.Intent; |
| 8 | +import android.os.Build; | ||
| 8 | import android.os.Bundle; | 9 | import android.os.Bundle; |
| 10 | +import android.os.Environment; | ||
| 9 | import android.view.View; | 11 | import android.view.View; |
| 10 | 12 | ||
| 11 | import com.cnlive.media.ImagePicker; | 13 | import com.cnlive.media.ImagePicker; |
| 12 | import com.cnlive.media.PickerConfig; | 14 | import com.cnlive.media.PickerConfig; |
| 13 | import com.cnlive.media.media.entity.Media; | 15 | import com.cnlive.media.media.entity.Media; |
| 16 | +import com.cnlive.media.utils.AndroidQUtil; | ||
| 14 | import com.cnlive.media.utils.GlideCacheUtil; | 17 | import com.cnlive.media.utils.GlideCacheUtil; |
| 15 | import com.cnlive.strike.debug.R; | 18 | import com.cnlive.strike.debug.R; |
| 16 | import com.cnlive.strike.debug.databinding.ActivityMainBinding; | 19 | import com.cnlive.strike.debug.databinding.ActivityMainBinding; |
| 17 | 20 | ||
| 21 | +import java.io.File; | ||
| 18 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
| 19 | 23 | ||
| 20 | 24 | ||
| @@ -22,12 +26,25 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | @@ -22,12 +26,25 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | ||
| 22 | 26 | ||
| 23 | private ActivityMainBinding mainBinding; | 27 | private ActivityMainBinding mainBinding; |
| 24 | private ArrayList<Media> select; | 28 | private ArrayList<Media> select; |
| 29 | + private String fileDir; | ||
| 25 | 30 | ||
| 26 | @Override | 31 | @Override |
| 27 | protected void onCreate(Bundle savedInstanceState) { | 32 | protected void onCreate(Bundle savedInstanceState) { |
| 28 | super.onCreate(savedInstanceState); | 33 | super.onCreate(savedInstanceState); |
| 29 | mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); | 34 | mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); |
| 30 | mainBinding.setOnClick(this); | 35 | mainBinding.setOnClick(this); |
| 36 | + | ||
| 37 | + | ||
| 38 | + boolean isAndroidQ = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; | ||
| 39 | + File fileQ = getExternalFilesDir(""); | ||
| 40 | + File file = Environment.getExternalStorageDirectory(); | ||
| 41 | + String filePath = null; | ||
| 42 | + if (isAndroidQ) { | ||
| 43 | + if (fileQ != null) filePath = fileQ + "/strike/file/"; | ||
| 44 | + } else { | ||
| 45 | + if (file != null) filePath = file + "/strike/file/"; | ||
| 46 | + } | ||
| 47 | + fileDir = filePath == null ? "" : filePath; | ||
| 31 | } | 48 | } |
| 32 | 49 | ||
| 33 | @Override | 50 | @Override |
| @@ -50,15 +67,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | @@ -50,15 +67,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | ||
| 50 | case R.id.tv_media: | 67 | case R.id.tv_media: |
| 51 | //打开相册 | 68 | //打开相册 |
| 52 | new ImagePicker.Builder() | 69 | new ImagePicker.Builder() |
| 70 | + .maxNum(5) | ||
| 53 | .setSelectGif(false) | 71 | .setSelectGif(false) |
| 72 | + .maxImageSize(25 * 1024 * 1024) | ||
| 73 | + .isReturnUri(AndroidQUtil.isAndroidQ()) | ||
| 74 | + .selectMode(PickerConfig.PICKER_ONLY_ONE_TYPE) | ||
| 75 | + .defaultSelectList(new ArrayList<Media>()) | ||
| 54 | .needCamera(true) | 76 | .needCamera(true) |
| 55 | - .maxNum(9) | ||
| 56 | - .selectMode(PickerConfig.PICKER_IMAGE_VIDEO) | ||
| 57 | - .maxVideoSize(100 * 1024 * 1024) | ||
| 58 | - .maxImageSize(1 * 1024 * 1024) | ||
| 59 | - .defaultSelectList(select) | ||
| 60 | -// .doCrop(1, 1, 900, 900) | 77 | + .cachePath(fileDir + "/strike/file/") |
| 78 | + .setJumpCameraMode(PickerConfig.CAMERA_MODE_PIC) | ||
| 61 | .builder() | 79 | .builder() |
| 80 | +// .doCrop(1, 1, 900, 900) | ||
| 62 | .start(this, PickerConfig.PICKER_IMAGE, PickerConfig.DEFAULT_RESULT_CODE); | 81 | .start(this, PickerConfig.PICKER_IMAGE, PickerConfig.DEFAULT_RESULT_CODE); |
| 63 | break; | 82 | break; |
| 64 | } | 83 | } |
config.gradle
lib_media/src/main/java/com/cnlive/media/frame/presenter/MediaPresenter.java
| @@ -75,6 +75,22 @@ public class MediaPresenter extends MvpBasePresenter<MediaView> { | @@ -75,6 +75,22 @@ public class MediaPresenter extends MvpBasePresenter<MediaView> { | ||
| 75 | mediaPickerActivity.isFrendCircle = mediaPickerActivity.mOptions.isFriendCircle(); | 75 | mediaPickerActivity.isFrendCircle = mediaPickerActivity.mOptions.isFriendCircle(); |
| 76 | mediaPickerActivity.needCrop = mediaPickerActivity.mOptions.isNeedCrop(); | 76 | mediaPickerActivity.needCrop = mediaPickerActivity.mOptions.isNeedCrop(); |
| 77 | mediaPickerActivity.needCamera = mediaPickerActivity.mOptions.isNeedCamera(); | 77 | mediaPickerActivity.needCamera = mediaPickerActivity.mOptions.isNeedCamera(); |
| 78 | + mediaPickerActivity.selectMode = mediaPickerActivity.mOptions.getSelectMode(); | ||
| 79 | + | ||
| 80 | + if (mediaPickerActivity.needCamera) { | ||
| 81 | + if (mediaPickerActivity.selectMode < 0) { | ||
| 82 | + mediaPickerActivity.selectMode = PickerConfig.PICKER_IMAGE_VIDEO; | ||
| 83 | + mediaPickerActivity.mOptions.setSelectMode(mediaPickerActivity.selectMode); | ||
| 84 | + mediaPickerActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_ALL); | ||
| 85 | + } else if (mediaPickerActivity.selectMode == PickerConfig.PICKER_IMAGE) { | ||
| 86 | + mediaPickerActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_PIC); | ||
| 87 | + } else if (mediaPickerActivity.selectMode == PickerConfig.PICKER_VIDEO) { | ||
| 88 | + mediaPickerActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_VIDEO); | ||
| 89 | + } else if (mediaPickerActivity.selectMode == PickerConfig.PICKER_ONLY_ONE_TYPE) { | ||
| 90 | + mediaPickerActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_ALL); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + | ||
| 78 | mediaPickerActivity.showTime = mediaPickerActivity.mOptions.isShowTime(); | 94 | mediaPickerActivity.showTime = mediaPickerActivity.mOptions.isShowTime(); |
| 79 | mediaPickerActivity.selectGift = mediaPickerActivity.mOptions.isSelectGift(); | 95 | mediaPickerActivity.selectGift = mediaPickerActivity.mOptions.isSelectGift(); |
| 80 | mediaPickerActivity.singlePick = mediaPickerActivity.mOptions.isSinglePick(); | 96 | mediaPickerActivity.singlePick = mediaPickerActivity.mOptions.isSinglePick(); |
lib_media/src/main/java/com/cnlive/media/frame/view/MediaFView.java
| 1 | package com.cnlive.media.frame.view; | 1 | package com.cnlive.media.frame.view; |
| 2 | 2 | ||
| 3 | +import android.content.Intent; | ||
| 4 | +import android.net.Uri; | ||
| 3 | import android.text.TextUtils; | 5 | import android.text.TextUtils; |
| 4 | import android.view.View; | 6 | import android.view.View; |
| 5 | 7 | ||
| 8 | +import androidx.annotation.Nullable; | ||
| 9 | + | ||
| 10 | +import com.bumptech.glide.load.DataSource; | ||
| 11 | +import com.bumptech.glide.load.engine.GlideException; | ||
| 12 | +import com.bumptech.glide.request.RequestListener; | ||
| 13 | +import com.bumptech.glide.request.target.Target; | ||
| 6 | import com.cnlive.libs.base.util.AlertUtil; | 14 | import com.cnlive.libs.base.util.AlertUtil; |
| 7 | import com.cnlive.media.media.entity.Media; | 15 | import com.cnlive.media.media.entity.Media; |
| 8 | import com.cnlive.media.ui.activity.VideoPlayerActivity; | 16 | import com.cnlive.media.ui.activity.VideoPlayerActivity; |
| @@ -34,14 +42,37 @@ public class MediaFView implements MvpView { | @@ -34,14 +42,37 @@ public class MediaFView implements MvpView { | ||
| 34 | //是视频 | 42 | //是视频 |
| 35 | mFragment.binding.lvLoading.setVisibility(View.VISIBLE); | 43 | mFragment.binding.lvLoading.setVisibility(View.VISIBLE); |
| 36 | if (mFragment.mMedia.mediaType == 3) { | 44 | if (mFragment.mMedia.mediaType == 3) { |
| 37 | - mFragment.binding.playView.setVisibility(View.VISIBLE); | ||
| 38 | mFragment.binding.photoview.setVisibility(View.GONE); | 45 | mFragment.binding.photoview.setVisibility(View.GONE); |
| 39 | mFragment.binding.largePhoto.setVisibility(View.GONE); | 46 | mFragment.binding.largePhoto.setVisibility(View.GONE); |
| 40 | mFragment.binding.gifView.setVisibility(View.VISIBLE); | 47 | mFragment.binding.gifView.setVisibility(View.VISIBLE); |
| 41 | - GlideCacheUtil.intoItemImage(mFragment.getActivity(), mFragment.mMedia, mFragment.binding.gifView, mFragment.binding.lvLoading); | 48 | +// GlideCacheUtil.intoItemImage(mFragment.getActivity(), mFragment.mMedia, mFragment.binding.gifView, mFragment.binding.lvLoading); |
| 49 | + GlideCacheUtil.intoItemImageListener(mFragment.getActivity(), mFragment.mMedia, mFragment.binding.gifView, new RequestListener() { | ||
| 50 | + @Override | ||
| 51 | + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { | ||
| 52 | + if (mFragment.binding.lvLoading != null) mFragment.binding.lvLoading .setVisibility(View.GONE); | ||
| 53 | + return false; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { | ||
| 58 | + mFragment.binding.playView.setVisibility(View.VISIBLE); | ||
| 59 | + if (mFragment.binding.lvLoading != null) mFragment.binding.lvLoading.setVisibility(View.GONE); | ||
| 60 | + return false; | ||
| 61 | + } | ||
| 62 | + }); | ||
| 42 | 63 | ||
| 43 | mFragment.binding.playView.setOnClickListener(v -> { | 64 | mFragment.binding.playView.setOnClickListener(v -> { |
| 44 | - VideoPlayerActivity.newInstance(mFragment.getActivity(), mFragment.mMedia.fileUri); | 65 | + |
| 66 | + Uri uri = Uri.parse(mFragment.mMedia.fileUri); | ||
| 67 | + Intent intent = new Intent(Intent.ACTION_VIEW); | ||
| 68 | + intent.setDataAndType(uri, "video/*"); | ||
| 69 | + if (mFragment.getActivity().getPackageManager().queryIntentActivities(intent, 0).isEmpty()) { | ||
| 70 | + AlertUtil.showDeftToast(mFragment.getActivity(), "未检测到播放器"); | ||
| 71 | + } else { | ||
| 72 | + mFragment.startActivity(intent); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | +// VideoPlayerActivity.newInstance(mFragment.getActivity(), mFragment.mMedia.fileUri); | ||
| 45 | }); | 76 | }); |
| 46 | } else { | 77 | } else { |
| 47 | if (FileTypeUtil.isGif(mFragment.mMedia.path)) { | 78 | if (FileTypeUtil.isGif(mFragment.mMedia.path)) { |
lib_media/src/main/java/com/cnlive/media/frame/view/MediaPreviewViewView.java
| @@ -51,38 +51,39 @@ public class MediaPreviewViewView implements MvpView { | @@ -51,38 +51,39 @@ public class MediaPreviewViewView implements MvpView { | ||
| 51 | mActivity.finish(); | 51 | mActivity.finish(); |
| 52 | }); | 52 | }); |
| 53 | mActivity.currentMedia = mActivity.selectLists.get(mActivity.position); | 53 | mActivity.currentMedia = mActivity.selectLists.get(mActivity.position); |
| 54 | - if (mActivity.currentMedia.isSelect()) { | ||
| 55 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 56 | - } else { | ||
| 57 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 58 | - } | ||
| 59 | - mActivity.currentArray.addAll(mActivity.selectLists); | ||
| 60 | - mActivity.binding.preTop.findViewById(R.id.check_layout_top).setOnClickListener(v -> { | ||
| 61 | - if (mActivity.currentMedia != null) { | ||
| 62 | - int pos = mActivity.selectLists.indexOf(mActivity.currentMedia); | ||
| 63 | - if (mActivity.currentMedia.isSelect()) { | ||
| 64 | - if (mActivity.currentArray.contains(mActivity.currentMedia)) { | ||
| 65 | - mActivity.currentArray.remove(mActivity.currentMedia); | ||
| 66 | - } | ||
| 67 | - mActivity.currentMedia.setSelect(false); | ||
| 68 | - if (mActivity.currentArray.contains(mActivity.currentMedia)) | ||
| 69 | - mActivity.selectLists.get(pos).setSelect(false); | ||
| 70 | - } else { | ||
| 71 | - mActivity.currentMedia.setSelect(true); | ||
| 72 | - mActivity.selectLists.get(pos).setSelect(true); | ||
| 73 | - if (!mActivity.currentArray.contains(mActivity.currentMedia)) { | ||
| 74 | - mActivity.currentArray.add(mActivity.currentMedia); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - } | ||
| 78 | - if (mActivity.currentMedia.isSelect()) { | ||
| 79 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 80 | - } else { | ||
| 81 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 82 | - } | ||
| 83 | - } | ||
| 84 | - }); | ||
| 85 | - mActivity.binding.preTop.findViewById(R.id.done).setVisibility(View.VISIBLE); | 54 | + mActivity.binding.preTop.findViewById(R.id.check_layout_top).setVisibility(View.GONE); |
| 55 | +// if (mActivity.currentMedia.isSelect()) { | ||
| 56 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 57 | +// } else { | ||
| 58 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 59 | +// } | ||
| 60 | +// mActivity.currentArray.addAll(mActivity.selectLists); | ||
| 61 | +// mActivity.binding.preTop.findViewById(R.id.check_layout_top).setOnClickListener(v -> { | ||
| 62 | +// if (mActivity.currentMedia != null) { | ||
| 63 | +// int pos = mActivity.selectLists.indexOf(mActivity.currentMedia); | ||
| 64 | +// if (mActivity.currentMedia.isSelect()) { | ||
| 65 | +// if (mActivity.currentArray.contains(mActivity.currentMedia)) { | ||
| 66 | +// mActivity.currentArray.remove(mActivity.currentMedia); | ||
| 67 | +// } | ||
| 68 | +// mActivity.currentMedia.setSelect(false); | ||
| 69 | +// if (mActivity.currentArray.contains(mActivity.currentMedia)) | ||
| 70 | +// mActivity.selectLists.get(pos).setSelect(false); | ||
| 71 | +// } else { | ||
| 72 | +// mActivity.currentMedia.setSelect(true); | ||
| 73 | +// mActivity.selectLists.get(pos).setSelect(true); | ||
| 74 | +// if (!mActivity.currentArray.contains(mActivity.currentMedia)) { | ||
| 75 | +// mActivity.currentArray.add(mActivity.currentMedia); | ||
| 76 | +// } | ||
| 77 | +// | ||
| 78 | +// } | ||
| 79 | +// if (mActivity.currentMedia.isSelect()) { | ||
| 80 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 81 | +// } else { | ||
| 82 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 83 | +// } | ||
| 84 | +// } | ||
| 85 | +// }); | ||
| 86 | + mActivity.binding.preTop.findViewById(R.id.done).setVisibility(View.GONE); | ||
| 86 | mActivity.binding.preTop.findViewById(R.id.done).setOnClickListener(v -> { | 87 | mActivity.binding.preTop.findViewById(R.id.done).setOnClickListener(v -> { |
| 87 | //返回 | 88 | //返回 |
| 88 | finishMedia(); | 89 | finishMedia(); |
| @@ -93,7 +94,6 @@ public class MediaPreviewViewView implements MvpView { | @@ -93,7 +94,6 @@ public class MediaPreviewViewView implements MvpView { | ||
| 93 | String barTitleText = String.format(mActivity.getResources().getString(R.string.btn_bar_title), mActivity.position + 1, mActivity.selectLists.size()); | 94 | String barTitleText = String.format(mActivity.getResources().getString(R.string.btn_bar_title), mActivity.position + 1, mActivity.selectLists.size()); |
| 94 | ((TextView) mActivity.binding.preTop.findViewById(R.id.bar_title)).setText(barTitleText); | 95 | ((TextView) mActivity.binding.preTop.findViewById(R.id.bar_title)).setText(barTitleText); |
| 95 | 96 | ||
| 96 | - mActivity.binding.preTop.findViewById(R.id.check_layout_top).setVisibility(View.VISIBLE); | ||
| 97 | 97 | ||
| 98 | mActivity.binding.vpPreview.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { | 98 | mActivity.binding.vpPreview.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
| 99 | @Override | 99 | @Override |
| @@ -121,13 +121,13 @@ public class MediaPreviewViewView implements MvpView { | @@ -121,13 +121,13 @@ public class MediaPreviewViewView implements MvpView { | ||
| 121 | public void showSelectPrew(Media media) { | 121 | public void showSelectPrew(Media media) { |
| 122 | String barTitleText = String.format(mActivity.getResources().getString(R.string.btn_bar_title), mActivity.selectLists.indexOf(media) + 1, mActivity.selectLists.size()); | 122 | String barTitleText = String.format(mActivity.getResources().getString(R.string.btn_bar_title), mActivity.selectLists.indexOf(media) + 1, mActivity.selectLists.size()); |
| 123 | ((TextView) mActivity.binding.preTop.findViewById(R.id.bar_title)).setText(barTitleText); | 123 | ((TextView) mActivity.binding.preTop.findViewById(R.id.bar_title)).setText(barTitleText); |
| 124 | - mActivity.binding.preTop.findViewById(R.id.check_layout_top).setVisibility(View.VISIBLE); | ||
| 125 | - | ||
| 126 | - if (media.isSelect()) { | ||
| 127 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 128 | - } else { | ||
| 129 | - ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 130 | - } | 124 | +// mActivity.binding.preTop.findViewById(R.id.check_layout_top).setVisibility(View.VISIBLE); |
| 125 | +// | ||
| 126 | +// if (media.isSelect()) { | ||
| 127 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_xuanzhong); | ||
| 128 | +// } else { | ||
| 129 | +// ((ImageView) mActivity.binding.preTop.findViewById(R.id.check_image_top)).setImageResource(R.drawable.xc_weixuan); | ||
| 130 | +// } | ||
| 131 | 131 | ||
| 132 | } | 132 | } |
| 133 | 133 |
lib_media/src/main/java/com/cnlive/media/frame/view/MediaView.java
| @@ -87,14 +87,14 @@ public class MediaView implements MvpView { | @@ -87,14 +87,14 @@ public class MediaView implements MvpView { | ||
| 87 | checkLayout = mActivity.binding.top.findViewById(R.id.check_layout_top); | 87 | checkLayout = mActivity.binding.top.findViewById(R.id.check_layout_top); |
| 88 | checkImage = mActivity.binding.top.findViewById(R.id.check_image_top); | 88 | checkImage = mActivity.binding.top.findViewById(R.id.check_image_top); |
| 89 | bottomRv = mActivity.binding.bottom.findViewById(R.id.bottom_recycler_view); | 89 | bottomRv = mActivity.binding.bottom.findViewById(R.id.bottom_recycler_view); |
| 90 | - checkImage.setOnClickListener(mActivity); | 90 | + checkLayout.setOnClickListener(mActivity); |
| 91 | bDone.setOnClickListener(mActivity); | 91 | bDone.setOnClickListener(mActivity); |
| 92 | 92 | ||
| 93 | initState(); | 93 | initState(); |
| 94 | setSelectText(null); | 94 | setSelectText(null); |
| 95 | setTitleBar(); | 95 | setTitleBar(); |
| 96 | initFolder(); | 96 | initFolder(); |
| 97 | - if (mActivity.needCrop) { | 97 | + if (mActivity.needCrop || mActivity.singlePick || mActivity.maxNum == 1) { |
| 98 | preview.setVisibility(View.GONE); | 98 | preview.setVisibility(View.GONE); |
| 99 | } else { | 99 | } else { |
| 100 | preview.setVisibility(View.VISIBLE); | 100 | preview.setVisibility(View.VISIBLE); |
| @@ -132,12 +132,16 @@ public class MediaView implements MvpView { | @@ -132,12 +132,16 @@ public class MediaView implements MvpView { | ||
| 132 | 132 | ||
| 133 | if (type == PickerConfig.PICKER_IMAGE_VIDEO) { | 133 | if (type == PickerConfig.PICKER_IMAGE_VIDEO) { |
| 134 | barTitle.setText(mActivity.getResources().getString(R.string.select_title)); | 134 | barTitle.setText(mActivity.getResources().getString(R.string.select_title)); |
| 135 | + ((Button) mActivity.binding.footer.findViewById(R.id.category_btn)).setText(mActivity.getResources().getString(R.string.select_title)); | ||
| 135 | } else if (type == PickerConfig.PICKER_ONLY_ONE_TYPE) { | 136 | } else if (type == PickerConfig.PICKER_ONLY_ONE_TYPE) { |
| 137 | + ((Button) mActivity.binding.footer.findViewById(R.id.category_btn)).setText(mActivity.getResources().getString(R.string.select_title)); | ||
| 136 | barTitle.setText(mActivity.getResources().getString(R.string.select_title)); | 138 | barTitle.setText(mActivity.getResources().getString(R.string.select_title)); |
| 137 | } else if (type == PickerConfig.PICKER_IMAGE) { | 139 | } else if (type == PickerConfig.PICKER_IMAGE) { |
| 138 | barTitle.setText(mActivity.getResources().getString(R.string.select_image_title)); | 140 | barTitle.setText(mActivity.getResources().getString(R.string.select_image_title)); |
| 141 | + ((Button) mActivity.binding.footer.findViewById(R.id.category_btn)).setText(mActivity.getResources().getString(R.string.select_image_title)); | ||
| 139 | } else if (type == PickerConfig.PICKER_VIDEO) { | 142 | } else if (type == PickerConfig.PICKER_VIDEO) { |
| 140 | barTitle.setText(mActivity.getResources().getString(R.string.select_video_title)); | 143 | barTitle.setText(mActivity.getResources().getString(R.string.select_video_title)); |
| 144 | + ((Button) mActivity.binding.footer.findViewById(R.id.category_btn)).setText(mActivity.getResources().getString(R.string.select_video_title)); | ||
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | 147 | ||
| @@ -188,13 +192,27 @@ public class MediaView implements MvpView { | @@ -188,13 +192,27 @@ public class MediaView implements MvpView { | ||
| 188 | } | 192 | } |
| 189 | 193 | ||
| 190 | /** | 194 | /** |
| 195 | + * 设置单选模式的拍照类型 | ||
| 196 | + */ | ||
| 197 | + public void setSingleMode(Media media) { | ||
| 198 | + //设置单选模式 | ||
| 199 | + if (mActivity.mOptions.getSelectMode() == PickerConfig.PICKER_ONLY_ONE_TYPE) { | ||
| 200 | + if (media.mediaType == 1) { | ||
| 201 | + mActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_PIC); | ||
| 202 | + } else if (media.mediaType == 3) { | ||
| 203 | + mActivity.mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_VIDEO); | ||
| 204 | + } | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + /** | ||
| 191 | * 处理选中的数据 | 209 | * 处理选中的数据 |
| 192 | * | 210 | * |
| 193 | * @param media | 211 | * @param media |
| 194 | */ | 212 | */ |
| 195 | public void progressSelectMedia(Media media) { | 213 | public void progressSelectMedia(Media media) { |
| 196 | if (media == null) return; | 214 | if (media == null) return; |
| 197 | - | 215 | + setSingleMode(media); |
| 198 | if (isCheckMediaSupport(media)) { | 216 | if (isCheckMediaSupport(media)) { |
| 199 | if (media.isSelect() && mActivity.selects.contains(media)) { | 217 | if (media.isSelect() && mActivity.selects.contains(media)) { |
| 200 | media.setSelect(!media.isSelect()); | 218 | media.setSelect(!media.isSelect()); |
lib_media/src/main/java/com/cnlive/media/frame/view/RecordFragmentView.java
| @@ -59,6 +59,10 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -59,6 +59,10 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | public void initView() { | 61 | public void initView() { |
| 62 | + if (getActivity().mOptions == null) { | ||
| 63 | + showMesage("数据异常"); | ||
| 64 | + mFragment.getActivity().finish(); | ||
| 65 | + } | ||
| 62 | // 摄像头采集选项 | 66 | // 摄像头采集选项 |
| 63 | if (mFragment.plShortVideoRecorder == null) | 67 | if (mFragment.plShortVideoRecorder == null) |
| 64 | mFragment.plShortVideoRecorder = new PLShortVideoRecorder(); | 68 | mFragment.plShortVideoRecorder = new PLShortVideoRecorder(); |
| @@ -83,14 +87,19 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -83,14 +87,19 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 83 | // 录制选项 | 87 | // 录制选项 |
| 84 | recordSetting = new PLRecordSetting(); | 88 | recordSetting = new PLRecordSetting(); |
| 85 | // 最大录制时常 | 89 | // 最大录制时常 |
| 86 | - recordSetting.setMaxRecordDuration(getActivity() .mOptions.getMaxTime()); | 90 | + if (getActivity().mOptions != null && getActivity().mOptions.getMaxTime() > 0) { |
| 91 | + recordSetting.setMaxRecordDuration(getActivity().mOptions.getMaxTime()); | ||
| 92 | + } else { | ||
| 93 | + recordSetting.setMaxRecordDuration(60 * 1000); | ||
| 94 | + } | ||
| 95 | + | ||
| 87 | recordSetting.setRecordSpeedVariable(true); | 96 | recordSetting.setRecordSpeedVariable(true); |
| 88 | recordSetting.setDisplayMode(PLDisplayMode.FULL); | 97 | recordSetting.setDisplayMode(PLDisplayMode.FULL); |
| 89 | 98 | ||
| 90 | 99 | ||
| 91 | - if (TextUtils.isEmpty(getActivity() .mOptions.getCachePath())) { | 100 | + if (getActivity().mOptions == null || TextUtils.isEmpty(getActivity().mOptions.getCachePath())) { |
| 92 | if (AndroidQUtil.isAndroidQ()) { | 101 | if (AndroidQUtil.isAndroidQ()) { |
| 93 | - videoCaceDirPath = getActivity() .getExternalFilesDir("").getPath() + File.separator + "MediaPickerVideo"; | 102 | + videoCaceDirPath = getActivity().getExternalFilesDir("").getPath() + File.separator + "MediaPickerVideo"; |
| 94 | } else { | 103 | } else { |
| 95 | videoCaceDirPath = Environment.getExternalStorageDirectory().getPath() + File.separator + "MediaPickerVideo"; | 104 | videoCaceDirPath = Environment.getExternalStorageDirectory().getPath() + File.separator + "MediaPickerVideo"; |
| 96 | } | 105 | } |
| @@ -98,16 +107,16 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -98,16 +107,16 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 98 | if (AndroidQUtil.isAndroidQ()) { | 107 | if (AndroidQUtil.isAndroidQ()) { |
| 99 | videoCaceDirPath = mFragment.getActivity().getExternalFilesDir("").getPath() + File.separator + "MediaPickerVideo"; | 108 | videoCaceDirPath = mFragment.getActivity().getExternalFilesDir("").getPath() + File.separator + "MediaPickerVideo"; |
| 100 | } else { | 109 | } else { |
| 101 | - videoCaceDirPath = getActivity() .mOptions.getCachePath(); | 110 | + videoCaceDirPath = getActivity().mOptions.getCachePath(); |
| 102 | } | 111 | } |
| 103 | } | 112 | } |
| 104 | - getActivity() .mOptions.setCachePath(videoCaceDirPath); | 113 | + getActivity().mOptions.setCachePath(videoCaceDirPath); |
| 105 | recordSetting.setVideoCacheDir(videoCaceDirPath); | 114 | recordSetting.setVideoCacheDir(videoCaceDirPath); |
| 106 | 115 | ||
| 107 | - getActivity() .videoPath = getActivity() .mOptions.getCachePath() + System.currentTimeMillis() + ".mp4"; | ||
| 108 | - recordSetting.setVideoFilepath(getActivity() .videoPath); | 116 | + getActivity().videoPath = getActivity().mOptions.getCachePath() + System.currentTimeMillis() + ".mp4"; |
| 117 | + recordSetting.setVideoFilepath(getActivity().videoPath); | ||
| 109 | mFragment.binding.rcControl.setFlashState(false); | 118 | mFragment.binding.rcControl.setFlashState(false); |
| 110 | - mFragment.binding.rcControl.setMaxTime(getActivity() .mOptions.getMaxTime()); | 119 | + mFragment.binding.rcControl.setMaxTime(getActivity().mOptions.getMaxTime()); |
| 111 | 120 | ||
| 112 | //设置闪光灯 | 121 | //设置闪光灯 |
| 113 | 122 | ||
| @@ -127,10 +136,10 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -127,10 +136,10 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 127 | } | 136 | } |
| 128 | }); | 137 | }); |
| 129 | //如果是裁剪类型只支持拍照 | 138 | //如果是裁剪类型只支持拍照 |
| 130 | - if (getActivity() .isJumpCamera && getActivity() .mOptions.getJumpCameraMode() >= 0) { | ||
| 131 | - mFragment.binding.rcControl.setRecordType(getActivity() .mOptions.getJumpCameraMode()); | 139 | + if (getActivity().isJumpCamera || getActivity().mOptions.getJumpCameraMode() >= 0) { |
| 140 | + mFragment.binding.rcControl.setRecordType(getActivity().mOptions.getJumpCameraMode()); | ||
| 132 | } else { | 141 | } else { |
| 133 | - if (getActivity() .mOptions.isNeedCrop()) { | 142 | + if (getActivity().mOptions.isNeedCrop()) { |
| 134 | mFragment.binding.rcControl.setRecordType(PickerConfig.CAMERA_MODE_PIC); | 143 | mFragment.binding.rcControl.setRecordType(PickerConfig.CAMERA_MODE_PIC); |
| 135 | } else { | 144 | } else { |
| 136 | mFragment.binding.rcControl.setRecordType(PickerConfig.CAMERA_MODE_ALL); | 145 | mFragment.binding.rcControl.setRecordType(PickerConfig.CAMERA_MODE_ALL); |
| @@ -140,6 +149,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -140,6 +149,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 140 | 149 | ||
| 141 | /** | 150 | /** |
| 142 | * 选择相机 | 151 | * 选择相机 |
| 152 | + * | ||
| 143 | * @return | 153 | * @return |
| 144 | */ | 154 | */ |
| 145 | private PLCameraSetting.CAMERA_FACING_ID chooseCameraFacingId() { | 155 | private PLCameraSetting.CAMERA_FACING_ID chooseCameraFacingId() { |
| @@ -154,6 +164,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -154,6 +164,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 154 | 164 | ||
| 155 | /** | 165 | /** |
| 156 | * 设置闪光灯 | 166 | * 设置闪光灯 |
| 167 | + * | ||
| 157 | * @param isFlashingState | 168 | * @param isFlashingState |
| 158 | */ | 169 | */ |
| 159 | public void processFlash(boolean isFlashingState) { | 170 | public void processFlash(boolean isFlashingState) { |
| @@ -162,6 +173,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -162,6 +173,7 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 162 | 173 | ||
| 163 | /** | 174 | /** |
| 164 | * 异常 | 175 | * 异常 |
| 176 | + * | ||
| 165 | * @param message | 177 | * @param message |
| 166 | */ | 178 | */ |
| 167 | public void showMesage(String message) { | 179 | public void showMesage(String message) { |
| @@ -245,7 +257,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -245,7 +257,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 245 | } | 257 | } |
| 246 | 258 | ||
| 247 | 259 | ||
| 248 | - | ||
| 249 | @Override | 260 | @Override |
| 250 | public void onReady() { | 261 | public void onReady() { |
| 251 | //设置闪光灯 | 262 | //设置闪光灯 |
lib_media/src/main/java/com/cnlive/media/frame/view/RecordView.java
| @@ -61,9 +61,12 @@ public class RecordView implements MvpView { | @@ -61,9 +61,12 @@ public class RecordView implements MvpView { | ||
| 61 | 61 | ||
| 62 | //检测权限 | 62 | //检测权限 |
| 63 | public void checkPermisssion() { | 63 | public void checkPermisssion() { |
| 64 | - | ||
| 65 | - boolean hasPermissions = mActivity.getPresenter() | ||
| 66 | - .checkPermissions(mActivity, mActivity.permissionsRecord, mActivity.PERMISISSION_CODE_ASK, true); | 64 | + boolean hasPermissions; |
| 65 | + if (mActivity.isNeedAudio){ | ||
| 66 | + hasPermissions = mActivity.getPresenter().checkPermissions(mActivity, mActivity.permissionsRecord, mActivity.PERMISISSION_CODE_ASK, true); | ||
| 67 | + }else { | ||
| 68 | + hasPermissions = mActivity.getPresenter().checkPermissions(mActivity, mActivity.permissionsRecordNoAudio, mActivity.PERMISISSION_CODE_ASK, true); | ||
| 69 | + } | ||
| 67 | if (hasPermissions) { | 70 | if (hasPermissions) { |
| 68 | mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.pre_frame, RecordFragment.newInstance()).addToBackStack("").commit(); | 71 | mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.pre_frame, RecordFragment.newInstance()).addToBackStack("").commit(); |
| 69 | } | 72 | } |
lib_media/src/main/java/com/cnlive/media/ui/activity/MediaActivity.java
| @@ -222,6 +222,8 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | @@ -222,6 +222,8 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | ||
| 222 | if (currentFragment instanceof MediaPickerFragment) { | 222 | if (currentFragment instanceof MediaPickerFragment) { |
| 223 | MediaPickerFragment mediaPickerFragment = (MediaPickerFragment) currentFragment; | 223 | MediaPickerFragment mediaPickerFragment = (MediaPickerFragment) currentFragment; |
| 224 | mediaPickerFragment.addMedia(media); | 224 | mediaPickerFragment.addMedia(media); |
| 225 | + getMvpView().setSingleMode(media); | ||
| 226 | + | ||
| 225 | } | 227 | } |
| 226 | } | 228 | } |
| 227 | } else if (o instanceof MeidaResultObservable) { | 229 | } else if (o instanceof MeidaResultObservable) { |
| @@ -280,7 +282,7 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | @@ -280,7 +282,7 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | ||
| 280 | } else { | 282 | } else { |
| 281 | addPrePreviewFragment(selects.get(0), true); | 283 | addPrePreviewFragment(selects.get(0), true); |
| 282 | } | 284 | } |
| 283 | - } else if (viewId == R.id.check_image_top) { | 285 | + } else if (viewId == R.id.check_layout_top) { |
| 284 | getMvpView().processCheckMeida(); | 286 | getMvpView().processCheckMeida(); |
| 285 | } | 287 | } |
| 286 | } | 288 | } |
lib_media/src/main/java/com/cnlive/media/ui/activity/RecordActivity.java
| @@ -54,10 +54,10 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | @@ -54,10 +54,10 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | ||
| 54 | //是否没有申请权限 | 54 | //是否没有申请权限 |
| 55 | public boolean isNeverAsk; | 55 | public boolean isNeverAsk; |
| 56 | public ArrayList<Media> selectMedia; | 56 | public ArrayList<Media> selectMedia; |
| 57 | - // 存读取权限 | ||
| 58 | - | ||
| 59 | - public static String[] permissionsRecord = { | ||
| 60 | - Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | 57 | + // 是否需要录音权限 |
| 58 | + public boolean isNeedAudio = true; | ||
| 59 | + public static String[] permissionsRecord = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | ||
| 60 | + public static String[] permissionsRecordNoAudio = {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO,Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | ||
| 61 | 61 | ||
| 62 | public static void newInstance(Context context, ImagePickerOptions mOptions) { | 62 | public static void newInstance(Context context, ImagePickerOptions mOptions) { |
| 63 | Intent intent = new Intent(); | 63 | Intent intent = new Intent(); |
| @@ -84,6 +84,18 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | @@ -84,6 +84,18 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | ||
| 84 | selectMedia = getIntent().getParcelableArrayListExtra(PickerConfig.WHERE_JUMP_CAMERA_SELECTS); | 84 | selectMedia = getIntent().getParcelableArrayListExtra(PickerConfig.WHERE_JUMP_CAMERA_SELECTS); |
| 85 | mOptions = getIntent().getParcelableExtra(PickerConfig.INTENT_KEY_OPTIONS); | 85 | mOptions = getIntent().getParcelableExtra(PickerConfig.INTENT_KEY_OPTIONS); |
| 86 | MeidaResultObservable.getInstance().addObserver(this); | 86 | MeidaResultObservable.getInstance().addObserver(this); |
| 87 | + if (mOptions != null) { | ||
| 88 | + if (mOptions.getJumpCameraMode() == PickerConfig.CAMERA_MODE_PIC) { | ||
| 89 | + isNeedAudio = false; | ||
| 90 | + } else { | ||
| 91 | + mOptions.setJumpCameraMode(PickerConfig.CAMERA_MODE_ALL); | ||
| 92 | + isNeedAudio = true; | ||
| 93 | + } | ||
| 94 | + } else { | ||
| 95 | + getMvpView().showMessage("初始化异常"); | ||
| 96 | + onBackPressed(); | ||
| 97 | + } | ||
| 98 | + | ||
| 87 | if (getMvpView() != null) getMvpView().initView(); | 99 | if (getMvpView() != null) getMvpView().initView(); |
| 88 | } else { | 100 | } else { |
| 89 | getMvpView().showMessage("初始化异常"); | 101 | getMvpView().showMessage("初始化异常"); |
| @@ -130,7 +142,12 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | @@ -130,7 +142,12 @@ public class RecordActivity extends MvpBindingActivity<RecordView, RecordPresent | ||
| 130 | } else if (hasPermissions[1]) { //权限永久拒绝的处理 | 142 | } else if (hasPermissions[1]) { //权限永久拒绝的处理 |
| 131 | getMvpView().showPermissionPerpetual(requestCode); | 143 | getMvpView().showPermissionPerpetual(requestCode); |
| 132 | } else { //权限没有全部同意 | 144 | } else { //权限没有全部同意 |
| 133 | - getMvpView().showPermission(permissionsRecord, PERMISISSION_CODE_ASK); | 145 | + if (isNeedAudio) { |
| 146 | + getMvpView().showPermission(permissionsRecord, PERMISISSION_CODE_ASK); | ||
| 147 | + } else { | ||
| 148 | + getMvpView().showPermission(permissionsRecordNoAudio, PERMISISSION_CODE_ASK); | ||
| 149 | + } | ||
| 150 | + | ||
| 134 | } | 151 | } |
| 135 | } | 152 | } |
| 136 | 153 |
lib_media/src/main/java/com/cnlive/media/ui/fragment/MediaPreviewFragment.java
| @@ -95,7 +95,7 @@ public class MediaPreviewFragment extends MvpBindingFragment<MediaPreviewView, M | @@ -95,7 +95,7 @@ public class MediaPreviewFragment extends MvpBindingFragment<MediaPreviewView, M | ||
| 95 | */ | 95 | */ |
| 96 | public void showMediaPosition(Media meida) { | 96 | public void showMediaPosition(Media meida) { |
| 97 | int position = mediaPreviewAdapter.getMedias().indexOf(meida); | 97 | int position = mediaPreviewAdapter.getMedias().indexOf(meida); |
| 98 | - if (position>0) | 98 | + if (position>=0) |
| 99 | binding.viewpager.setCurrentItem(position); | 99 | binding.viewpager.setCurrentItem(position); |
| 100 | } | 100 | } |
| 101 | 101 |
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordFragment.java
| @@ -79,6 +79,7 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | @@ -79,6 +79,7 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | ||
| 79 | super.onResume(); | 79 | super.onResume(); |
| 80 | if (isFlash && getMvpView() != null) getMvpView().processFlash(isFlash); | 80 | if (isFlash && getMvpView() != null) getMvpView().processFlash(isFlash); |
| 81 | if (plShortVideoRecorder != null) plShortVideoRecorder.resume(); | 81 | if (plShortVideoRecorder != null) plShortVideoRecorder.resume(); |
| 82 | + plShortVideoRecorder.deleteLastSection(); | ||
| 82 | 83 | ||
| 83 | } | 84 | } |
| 84 | 85 | ||
| @@ -86,7 +87,10 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | @@ -86,7 +87,10 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | ||
| 86 | public void onPause() { | 87 | public void onPause() { |
| 87 | super.onPause(); | 88 | super.onPause(); |
| 88 | isRecordIng = false; | 89 | isRecordIng = false; |
| 89 | - if (plShortVideoRecorder != null) plShortVideoRecorder.pause(); | 90 | + if (plShortVideoRecorder != null) { |
| 91 | + binding.rcControl.resetRecord(); | ||
| 92 | + plShortVideoRecorder.pause(); | ||
| 93 | + } | ||
| 90 | } | 94 | } |
| 91 | 95 | ||
| 92 | @Override | 96 | @Override |
| @@ -152,7 +156,7 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | @@ -152,7 +156,7 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | ||
| 152 | //视频录制开始 | 156 | //视频录制开始 |
| 153 | if (isReady) { | 157 | if (isReady) { |
| 154 | isRecordIng = true; | 158 | isRecordIng = true; |
| 155 | - plShortVideoRecorder.deleteLastSection(); | 159 | +// plShortVideoRecorder.deleteLastSection(); |
| 156 | plShortVideoRecorder.beginSection(); | 160 | plShortVideoRecorder.beginSection(); |
| 157 | } else { | 161 | } else { |
| 158 | isRecordIng = false; | 162 | isRecordIng = false; |
| @@ -190,6 +194,9 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | @@ -190,6 +194,9 @@ public class RecordFragment extends MvpBindingFragment<RecordFragmentView, Recor | ||
| 190 | } | 194 | } |
| 191 | }); | 195 | }); |
| 192 | 196 | ||
| 197 | + } else if (state == RecordCameraViewObservable.CLICK_RECODE_ERR) { | ||
| 198 | + isRecordIng = false; | ||
| 199 | + | ||
| 193 | } | 200 | } |
| 194 | } | 201 | } |
| 195 | } | 202 | } |
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordPreviewFragment.java
| @@ -84,7 +84,6 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, | @@ -84,7 +84,6 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, | ||
| 84 | @Override | 84 | @Override |
| 85 | public void onResume() { | 85 | public void onResume() { |
| 86 | super.onResume(); | 86 | super.onResume(); |
| 87 | -// if (mShortVideoEditor != null) mShortVideoEditor.resumePlayback(); | ||
| 88 | if (type == 1&& getMvpView()!=null){ | 87 | if (type == 1&& getMvpView()!=null){ |
| 89 | getMvpView().initPre(); | 88 | getMvpView().initPre(); |
| 90 | } | 89 | } |
lib_media/src/main/java/com/cnlive/media/ui/widget/record/RecordCameraView.java
| @@ -80,6 +80,8 @@ public class RecordCameraView extends FrameLayout { | @@ -80,6 +80,8 @@ public class RecordCameraView extends FrameLayout { | ||
| 80 | 80 | ||
| 81 | @Override | 81 | @Override |
| 82 | public void onRecordVideoFail(String message) { | 82 | public void onRecordVideoFail(String message) { |
| 83 | + RecordCameraViewObservable.newInstance().onClick(RecordCameraViewObservable.CLICK_RECODE_ERR); | ||
| 84 | + | ||
| 83 | processErrMessage(message); | 85 | processErrMessage(message); |
| 84 | } | 86 | } |
| 85 | }); | 87 | }); |
| @@ -123,7 +125,8 @@ public class RecordCameraView extends FrameLayout { | @@ -123,7 +125,8 @@ public class RecordCameraView extends FrameLayout { | ||
| 123 | } | 125 | } |
| 124 | 126 | ||
| 125 | /** | 127 | /** |
| 126 | - * 设置最大时常 | 128 | + * 设置最大时常 |
| 129 | + * | ||
| 127 | * @param maxTime | 130 | * @param maxTime |
| 128 | */ | 131 | */ |
| 129 | public void setMaxTime(int maxTime) { | 132 | public void setMaxTime(int maxTime) { |
| @@ -134,10 +137,16 @@ public class RecordCameraView extends FrameLayout { | @@ -134,10 +137,16 @@ public class RecordCameraView extends FrameLayout { | ||
| 134 | 137 | ||
| 135 | /** | 138 | /** |
| 136 | * 设置录制类型 | 139 | * 设置录制类型 |
| 137 | - * @param type 1 拍照 2 视频 0 支持所有 | 140 | + * |
| 141 | + * @param type 1 拍照 2 视频 0 支持所有 | ||
| 138 | */ | 142 | */ |
| 139 | - public void setRecordType(int type){ | 143 | + public void setRecordType(int type) { |
| 140 | binding.shootView.setRecodeType(type); | 144 | binding.shootView.setRecodeType(type); |
| 141 | 145 | ||
| 142 | } | 146 | } |
| 147 | + | ||
| 148 | + public void resetRecord() { | ||
| 149 | + binding.shootView.reset(); | ||
| 150 | + | ||
| 151 | + } | ||
| 143 | } | 152 | } |
lib_media/src/main/java/com/cnlive/media/ui/widget/record/ShootView.java
| @@ -216,7 +216,7 @@ public class ShootView extends View implements Runnable { | @@ -216,7 +216,7 @@ public class ShootView extends View implements Runnable { | ||
| 216 | if (mListener != null && recordStart) { | 216 | if (mListener != null && recordStart) { |
| 217 | mListener.onFinishRecordVideo(); | 217 | mListener.onFinishRecordVideo(); |
| 218 | } else { | 218 | } else { |
| 219 | - mListener.onRecordVideoFail("录制事件过短"); | 219 | + mListener.onRecordVideoFail("录制时间过短"); |
| 220 | state = STATE_IDLE; | 220 | state = STATE_IDLE; |
| 221 | } | 221 | } |
| 222 | recordStart = false; | 222 | recordStart = false; |
| @@ -289,6 +289,16 @@ public class ShootView extends View implements Runnable { | @@ -289,6 +289,16 @@ public class ShootView extends View implements Runnable { | ||
| 289 | 289 | ||
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | + public void reset() { | ||
| 293 | + cutdownRatio = 0f; | ||
| 294 | + isShowProgress=false; | ||
| 295 | + recordStart=false; | ||
| 296 | + curProgress = 0; | ||
| 297 | + if (timer != null) timer.cancel(); | ||
| 298 | + state = STATE_IDLE; | ||
| 299 | + invalidate(); | ||
| 300 | + } | ||
| 301 | + | ||
| 292 | /** | 302 | /** |
| 293 | * 设置拍摄类型 | 303 | * 设置拍摄类型 |
| 294 | * | 304 | * |
lib_media/src/main/java/com/cnlive/media/ui/widget/record/observable/RecordCameraViewObservable.java
| @@ -24,6 +24,8 @@ public class RecordCameraViewObservable extends Observable { | @@ -24,6 +24,8 @@ public class RecordCameraViewObservable extends Observable { | ||
| 24 | public static int CLICK_RECODE_START = 5; | 24 | public static int CLICK_RECODE_START = 5; |
| 25 | //录制视频结束 | 25 | //录制视频结束 |
| 26 | public static int CLICK_RECODE_FINISH = 6; | 26 | public static int CLICK_RECODE_FINISH = 6; |
| 27 | + //录制异常 | ||
| 28 | + public static int CLICK_RECODE_ERR= 7; | ||
| 27 | 29 | ||
| 28 | static RecordCameraViewObservable instance; | 30 | static RecordCameraViewObservable instance; |
| 29 | 31 |
lib_media/src/main/java/com/cnlive/media/utils/GlideCacheUtil.java
| @@ -203,20 +203,22 @@ public class GlideCacheUtil { | @@ -203,20 +203,22 @@ public class GlideCacheUtil { | ||
| 203 | RequestManager rm = Glide.with(context); | 203 | RequestManager rm = Glide.with(context); |
| 204 | RequestBuilder rb = null; | 204 | RequestBuilder rb = null; |
| 205 | 205 | ||
| 206 | - view.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
| 207 | - | ||
| 208 | if (FileTypeUtil.isGif(media.path)) { | 206 | if (FileTypeUtil.isGif(media.path)) { |
| 209 | - rb = rm.asGif(); | ||
| 210 | - | 207 | +// rb = rm.asGif(); |
| 211 | } else { | 208 | } else { |
| 212 | option = option | 209 | option = option |
| 213 | .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) | 210 | .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) |
| 211 | + .centerCrop() | ||
| 214 | .dontAnimate(); | 212 | .dontAnimate(); |
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | if (media.mediaType == 1) { | 215 | if (media.mediaType == 1) { |
| 218 | option = option | 216 | option = option |
| 219 | .error(R.drawable.iv_imgload_full_err); | 217 | .error(R.drawable.iv_imgload_full_err); |
| 218 | + }else if (media.mediaType == 1){ | ||
| 219 | + option = option | ||
| 220 | + .error(R.drawable.iv_imgload_full_err); | ||
| 221 | + view.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
| 220 | } | 222 | } |
| 221 | 223 | ||
| 222 | if (AndroidQUtil.isAndroidQ()) { | 224 | if (AndroidQUtil.isAndroidQ()) { |
| @@ -247,6 +249,50 @@ public class GlideCacheUtil { | @@ -247,6 +249,50 @@ public class GlideCacheUtil { | ||
| 247 | } | 249 | } |
| 248 | 250 | ||
| 249 | 251 | ||
| 252 | + | ||
| 253 | + @SuppressLint("CheckResult") | ||
| 254 | + public static void intoItemImageListener(Context context, Media media, ImageView view, RequestListener listener) { | ||
| 255 | + if (context == null || media == null || view == null) return; | ||
| 256 | + | ||
| 257 | + RequestOptions option = new RequestOptions(); | ||
| 258 | + try { | ||
| 259 | + Uri mediaUri = Uri.parse(media.fileUri); | ||
| 260 | + | ||
| 261 | + RequestManager rm = Glide.with(context); | ||
| 262 | + RequestBuilder rb = null; | ||
| 263 | + | ||
| 264 | + if (FileTypeUtil.isGif(media.path)) { | ||
| 265 | +// rb = rm.asGif(); | ||
| 266 | + } else { | ||
| 267 | + option = option | ||
| 268 | + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) | ||
| 269 | + .centerCrop() | ||
| 270 | + .dontAnimate(); | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + if (media.mediaType == 1) { | ||
| 274 | + option = option | ||
| 275 | + .error(R.drawable.iv_imgload_full_err); | ||
| 276 | + view.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
| 277 | + }else if (media.mediaType == 3){ | ||
| 278 | + option = option | ||
| 279 | + .error(R.drawable.iv_imgload_full_err); | ||
| 280 | + | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + if (AndroidQUtil.isAndroidQ()) { | ||
| 284 | + rb = rb == null ? rm.load(mediaUri) : rb.load(mediaUri); | ||
| 285 | + } else { | ||
| 286 | + rb = rb == null ? rm.load(media.path) : rb.load(media.path); | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + rb.listener( listener).apply(option).into(view); | ||
| 290 | + } catch (Exception e) { | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + | ||
| 295 | + | ||
| 250 | @SuppressLint("CheckResult") | 296 | @SuppressLint("CheckResult") |
| 251 | public static void intoItemImageThumbnail(Context context, Media media, ImageView view, ProgressBar loading) { | 297 | public static void intoItemImageThumbnail(Context context, Media media, ImageView view, ProgressBar loading) { |
| 252 | if (context == null || media == null || view == null) return; | 298 | if (context == null || media == null || view == null) return; |
| @@ -262,7 +308,7 @@ public class GlideCacheUtil { | @@ -262,7 +308,7 @@ public class GlideCacheUtil { | ||
| 262 | view.setScaleType(ImageView.ScaleType.CENTER_CROP); | 308 | view.setScaleType(ImageView.ScaleType.CENTER_CROP); |
| 263 | 309 | ||
| 264 | if (FileTypeUtil.isGif(media.path)) { | 310 | if (FileTypeUtil.isGif(media.path)) { |
| 265 | - rb = rm.asGif(); | 311 | +// rb = rm.asGif(); |
| 266 | } else { | 312 | } else { |
| 267 | option = option | 313 | option = option |
| 268 | .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) | 314 | .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) |
| @@ -313,7 +359,7 @@ public class GlideCacheUtil { | @@ -313,7 +359,7 @@ public class GlideCacheUtil { | ||
| 313 | RequestManager rm = Glide.with(context); | 359 | RequestManager rm = Glide.with(context); |
| 314 | RequestBuilder rb = null; | 360 | RequestBuilder rb = null; |
| 315 | if (FileTypeUtil.isGif(media.path)) { | 361 | if (FileTypeUtil.isGif(media.path)) { |
| 316 | - rb = rm.asGif(); | 362 | +// rb = rm.asGif(); |
| 317 | } else { | 363 | } else { |
| 318 | option = option | 364 | option = option |
| 319 | .dontTransform() | 365 | .dontTransform() |
lib_media/src/main/java/com/cnlive/media/utils/album/AlbumProcessUtil.java
| @@ -12,6 +12,8 @@ import android.os.ParcelFileDescriptor; | @@ -12,6 +12,8 @@ import android.os.ParcelFileDescriptor; | ||
| 12 | import android.provider.MediaStore; | 12 | import android.provider.MediaStore; |
| 13 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
| 14 | 14 | ||
| 15 | +import com.cnlive.libs.base.util.FileUtils; | ||
| 16 | + | ||
| 15 | import java.io.File; | 17 | import java.io.File; |
| 16 | import java.io.FileInputStream; | 18 | import java.io.FileInputStream; |
| 17 | import java.io.FileNotFoundException; | 19 | import java.io.FileNotFoundException; |
| @@ -97,6 +99,101 @@ public class AlbumProcessUtil { | @@ -97,6 +99,101 @@ public class AlbumProcessUtil { | ||
| 97 | private static boolean isAdndroidQ() { | 99 | private static boolean isAdndroidQ() { |
| 98 | return Build.VERSION.SDK_INT >= 29; | 100 | return Build.VERSION.SDK_INT >= 29; |
| 99 | } | 101 | } |
| 102 | + /* | ||
| 103 | + * 保存bitmap到本地 | ||
| 104 | + * */ | ||
| 105 | + public static String saveBitmapNoInsert(Context context, Bitmap mBitmap) { | ||
| 106 | + String savePath; | ||
| 107 | + File filePic; | ||
| 108 | + savePath = getPath(context); | ||
| 109 | + try { | ||
| 110 | + filePic = new File(savePath + UUID.randomUUID().toString() + ".jpg"); | ||
| 111 | + if (!filePic.exists()) { | ||
| 112 | + filePic.getParentFile().mkdirs(); | ||
| 113 | + filePic.createNewFile(); | ||
| 114 | + } | ||
| 115 | + FileOutputStream fos = new FileOutputStream(filePic); | ||
| 116 | + mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); | ||
| 117 | + fos.flush(); | ||
| 118 | + fos.close(); | ||
| 119 | + | ||
| 120 | + } catch (IOException e) { | ||
| 121 | + e.printStackTrace(); | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + return filePic.getAbsolutePath(); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 保存bitmap | ||
| 130 | + * @param context | ||
| 131 | + * @param bitmap | ||
| 132 | + * @param callback | ||
| 133 | + */ | ||
| 134 | + public static void saveBitmapToGallery(Context context,final Bitmap bitmap, OnSaveCallback callback) { | ||
| 135 | + try { | ||
| 136 | + Observable.create(new ObservableOnSubscribe<String>() { | ||
| 137 | + @Override | ||
| 138 | + public void subscribe(ObservableEmitter<String> emitter) throws Exception { | ||
| 139 | + if (bitmap == null || bitmap.getByteCount() < 1) { | ||
| 140 | + emitter.onError(new Throwable("文件地址为空")); | ||
| 141 | + } else { | ||
| 142 | + | ||
| 143 | + String path = saveBitmapNoInsert(context, bitmap); | ||
| 144 | + | ||
| 145 | + if (FileUtils.isFileExists(path)) { | ||
| 146 | + if (isAdndroidQ()) { | ||
| 147 | + insertMediaImg(context, new File(path)); | ||
| 148 | + emitter.onNext(path); | ||
| 149 | + } else { | ||
| 150 | + insertMediaPic(context, new File(path)); | ||
| 151 | + context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path))); | ||
| 152 | + emitter.onNext(path); | ||
| 153 | + } | ||
| 154 | + } else { | ||
| 155 | + emitter.onError(new Throwable("图片保存失败")); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + | ||
| 161 | + }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() { | ||
| 162 | + @Override | ||
| 163 | + public void onSubscribe(Disposable d) { | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + @Override | ||
| 168 | + public void onNext(String s) { | ||
| 169 | + callback.onSuccess(s); | ||
| 170 | + if (bitmap!=null){ | ||
| 171 | + bitmap.recycle(); | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + @Override | ||
| 176 | + public void onError(Throwable e) { | ||
| 177 | + callback.onFail("文件保存失败"); | ||
| 178 | + if (bitmap!=null){ | ||
| 179 | + bitmap.recycle(); | ||
| 180 | + | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + @Override | ||
| 185 | + public void onComplete() { | ||
| 186 | + | ||
| 187 | + } | ||
| 188 | + }); | ||
| 189 | + | ||
| 190 | + } catch (Exception e) { | ||
| 191 | + if (e != null && e.getMessage() != null) { | ||
| 192 | + callback.onFail("文件保存失败"); | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + } | ||
| 100 | 197 | ||
| 101 | /** | 198 | /** |
| 102 | * 保存图片 小米 华为 vivo oppo 联想 锤子 三星 (部分机型) | 199 | * 保存图片 小米 华为 vivo oppo 联想 锤子 三星 (部分机型) |