Commit cf420cb6a35bbffcd46d015a2d772bb65b60c853

Authored by 吴奎庆
1 parent 8206d709

处理最大视频过滤

app/src/main/java/com/cnlive/strike/debug/MainActivity.java
... ... @@ -71,7 +71,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
71 71 .maxImageSize(25 * 1024 * 1024)
72 72 .maxVideoSize(100*1024*1024)
73 73 .isReturnUri(AndroidQUtil.isAndroidQ())
74   - .selectMode(PickerConfig.PICKER_ONLY_ONE_TYPE)
  74 + .selectMode(PickerConfig.PICKER_VIDEO)
75 75 .defaultSelectList(new ArrayList<Media>())
76 76 .needCamera(true)
77 77 .builder()
... ...
lib_media/src/main/java/com/cnlive/media/frame/view/MediaPickerFragmentView.java
... ... @@ -2,7 +2,6 @@ package com.cnlive.media.frame.view;
2 2  
3 3 import android.os.Build;
4 4 import android.text.TextUtils;
5   -import android.util.Log;
6 5  
7 6 import androidx.annotation.RequiresApi;
8 7 import androidx.recyclerview.widget.GridLayoutManager;
... ... @@ -12,12 +11,13 @@ import com.bumptech.glide.Glide;
12 11 import com.cnlive.libs.base.util.AlertUtil;
13 12 import com.cnlive.libs.base.util.DoublePressed;
14 13 import com.cnlive.media.PickerConfig;
  14 +import com.cnlive.media.R;
15 15 import com.cnlive.media.media.entity.Folder;
16 16 import com.cnlive.media.media.entity.Media;
17 17 import com.cnlive.media.ui.activity.MediaActivity;
18   -import com.cnlive.media.ui.fragment.MediaPickerFragment;
19 18 import com.cnlive.media.ui.adapter.MediaAdapter;
20 19 import com.cnlive.media.ui.adapter.OnItemClickListener;
  20 +import com.cnlive.media.ui.fragment.MediaPickerFragment;
21 21 import com.cnlive.media.ui.widget.SpacingDecoration;
22 22 import com.cnlive.media.utils.FileTypeUtil;
23 23 import com.cnlive.media.utils.MediaStringUtils;
... ... @@ -25,11 +25,9 @@ import com.cnlive.media.utils.observable.MediaOpenActivityObservable;
25 25 import com.cnlive.media.utils.observable.MediaOpenInfo;
26 26 import com.cnlive.media.utils.observable.MediaSelectStateObservable;
27 27 import com.cnlive.media.utils.observable.MeidaResultObservable;
28   -import com.cnlive.media.R;
29 28 import com.hannesdorfmann.mosby3.mvp.MvpView;
30 29  
31 30 import java.util.ArrayList;
32   -import java.util.List;
33 31  
34 32  
35 33 /**
... ... @@ -62,20 +60,18 @@ public class MediaPickerFragmentView implements MvpView {
62 60 //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
63 61 mFragment.binding.rv.setHasFixedSize(true);
64 62  
65   -// mFragment.binding.rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
66   -// @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
67   -// @Override
68   -// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
69   -// super.onScrollStateChanged(recyclerView, newState);
70   -// if (RecyclerView.SCROLL_STATE_IDLE == newState) {
71   -// Glide.with(recyclerView).resumeRequests();
72   -// Log.e("","");
73   -// } else {
74   -// Log.e("","");
75   -// Glide.with(recyclerView).pauseRequests();
76   -// }
77   -// }
78   -// });
  63 + mFragment.binding.rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
  64 + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
  65 + @Override
  66 + public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  67 + super.onScrollStateChanged(recyclerView, newState);
  68 + if (RecyclerView.SCROLL_STATE_IDLE == newState) {
  69 + Glide.with(recyclerView).resumeRequests();
  70 + } else {
  71 + Glide.with(recyclerView).pauseRequests();
  72 + }
  73 + }
  74 + });
79 75 mFragment.mMediaAdapter = new MediaAdapter(mFragment.getActivity(), mActivity.showTime, mActivity.mOptions);
80 76 mFragment.binding.rv.setAdapter(mFragment.mMediaAdapter);
81 77  
... ...
lib_media/src/main/java/com/cnlive/media/frame/view/RecordFragmentView.java
... ... @@ -60,7 +60,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener {
60 60  
61 61 public void initView() {
62 62  
63   - Log.e("启动流程","initView");
64 63 if (getActivity().mOptions == null) {
65 64 //Activity 缓存数据失效,一般情况是App被系统回收
66 65 return;
... ... @@ -112,7 +111,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener {
112 111 videoCaceDirPath = getActivity().mOptions.getCachePath();
113 112 }
114 113 }
115   - Log.e("启动流程","initView2");
116 114 getActivity().mOptions.setCachePath(videoCaceDirPath);
117 115 recordSetting.setVideoCacheDir(videoCaceDirPath);
118 116  
... ... @@ -275,17 +273,14 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener {
275 273  
276 274 @Override
277 275 public void onDurationTooShort() {
278   - Log.e("", "");
279 276 }
280 277  
281 278 @Override
282 279 public void onRecordStarted() {
283   - Log.e("", "");
284 280 }
285 281  
286 282 @Override
287 283 public void onSectionRecording(long l, long l1, int i) {
288   - Log.e("", "");
289 284 }
290 285  
291 286 @Override
... ... @@ -300,7 +295,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener {
300 295  
301 296 @Override
302 297 public void onSectionDecreased(long l, long l1, int i) {
303   - Log.e("", "");
304 298 }
305 299  
306 300 @Override
... ...
lib_media/src/main/java/com/cnlive/media/media/loader/VideoLoader.java
... ... @@ -37,6 +37,7 @@ public class VideoLoader extends LoaderM implements LoaderManager.LoaderCallback
37 37 MediaStore.Files.FileColumns.SIZE,
38 38 MediaStore.Files.FileColumns._ID,
39 39 MediaStore.Files.FileColumns.PARENT,
  40 + MediaStore.Video.VideoColumns._ID,
40 41 MediaStore.Video.VideoColumns.DURATION};
41 42  
42 43 Context mContext;
... ...
lib_media/src/main/java/com/cnlive/media/ui/activity/MediaActivity.java
... ... @@ -191,6 +191,8 @@ public class MediaActivity extends MvpBindingActivity&lt;MediaView, MediaPresenter,
191 191 ((MediaPickerFragment) currentFragment).setMediaData(list);
192 192 if (mFolderAdapter != null) mFolderAdapter.updateAdapter(list);
193 193 }
  194 +
  195 + ThumbnailsUtils.getThumbnails(this);
194 196 }
195 197  
196 198  
... ...
lib_media/src/main/java/com/cnlive/media/ui/fragment/RecordPreviewFragment.java
... ... @@ -117,7 +117,6 @@ public class RecordPreviewFragment extends MvpBindingFragment&lt;RecordPreviewView,
117 117 startActivity(intent);
118 118 }
119 119 } catch (Exception e) {
120   - Log.e("异常:", e.getMessage());
121 120 }
122 121  
123 122 } else if (v.getId() == R.id.tb_cancel) {
... ...
lib_media/src/main/java/com/cnlive/media/ui/widget/crop/CropUtil.java
... ... @@ -189,7 +189,6 @@ public class CropUtil {
189 189 System.gc();
190 190 resultPath = file.getAbsolutePath();
191 191 } catch (IOException e) {
192   - Log.e("CropUtils", "saveBmp(): savePath = " + savePath + "\nsaveName = " + saveName + "\n保存图片失败:" + e.toString());
193 192 }
194 193 return resultPath;
195 194 }
... ...
lib_media/src/main/java/com/cnlive/media/ui/widget/large/SubsamplingScaleImageView.java
... ... @@ -1649,7 +1649,6 @@ public class SubsamplingScaleImageView extends View {
1649 1649 return new int[]{sWidth, sHeight, exifOrientation};
1650 1650 }
1651 1651 } catch (Exception e) {
1652   - Log.e(TAG, "Failed to initialise bitmap decoder", e);
1653 1652 this.exception = e;
1654 1653 }
1655 1654 return null;
... ...
lib_media/src/main/java/com/cnlive/media/utils/GlideCacheUtil.java
... ... @@ -34,9 +34,16 @@ import com.bumptech.glide.request.target.Target;
34 34 import com.cnlive.media.media.entity.Media;
35 35 import com.cnlive.media.R;
36 36  
  37 +import org.reactivestreams.Subscriber;
  38 +import org.reactivestreams.Subscription;
  39 +
37 40 import java.io.File;
38 41 import java.math.BigDecimal;
39 42  
  43 +import io.reactivex.BackpressureStrategy;
  44 +import io.reactivex.Flowable;
  45 +import io.reactivex.FlowableEmitter;
  46 +import io.reactivex.FlowableOnSubscribe;
40 47 import io.reactivex.Observable;
41 48 import io.reactivex.ObservableEmitter;
42 49 import io.reactivex.ObservableOnSubscribe;
... ... @@ -322,7 +329,10 @@ public class GlideCacheUtil {
322 329 }
323 330 if (media.mediaType == 1) {
324 331 option = option.error(R.drawable.iv_imgload_full_err);
  332 + }else {
  333 + option = option.error(R.drawable.iv_imgload_full_err).placeholder(R.drawable.iv_imgload_full_err);
325 334 }
  335 +
326 336 if (AndroidQUtil.isAndroidQ()) {
327 337 showAndroidQ(context, media.mediaType, mediaUri, view, loading, option);
328 338 } else {
... ... @@ -330,8 +340,14 @@ public class GlideCacheUtil {
330 340 showNoAndroidQ(context, media.mediaType, media.path, view, loading, option);
331 341 // showImageThumbnail(context, media.mediaType, media.id, media.path, view, loading, option);
332 342 } else if (media.mediaType == 3) {
333   -// showNoAndroidQ(context, media.mediaType, media.path, view, loading, option);
334   - showVideoThumbnail(context, media.mediaType, media.id, media.path, view, loading, option);
  343 + if (ThumbnailsUtils.thumbnails.containsKey(media.id + "")) {
  344 + Log.e("包含:",ThumbnailsUtils.thumbnails.get(media.id + ""));
  345 + showVideoNoAndroidQ(context, media.mediaType, ThumbnailsUtils.thumbnails.get(media.id + ""), view, loading, option);
  346 + } else {
  347 + showVideoThumbnail(context, media.mediaType, media.id, media.path, view, loading, option);
  348 +// showVideoNoAndroidQ(context, media.mediaType, media.path, view, loading, option);
  349 + }
  350 +//
335 351 }
336 352  
337 353 }
... ... @@ -351,7 +367,7 @@ public class GlideCacheUtil {
351 367 Bitmap bm = contentResolver.loadThumbnail(mediaUri, new Size(100, 100), null);
352 368 emitter.onNext(bm);
353 369 }
354   - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {
  370 + }).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {
355 371 @Override
356 372 public void onSubscribe(Disposable d) {
357 373  
... ... @@ -391,97 +407,137 @@ public class GlideCacheUtil {
391 407 });
392 408 }
393 409  
  410 + private static void showVideoNoAndroidQ(Context context, int mediaType, String path, ImageView view, ProgressBar loading, RequestOptions option) {
  411 + RequestBuilder rb = Glide.with(context).load(path);
  412 + rb.listener(new RequestListener() {
  413 + @Override
  414 + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
  415 + view.setScaleType(ImageView.ScaleType.CENTER);
  416 + if (loading != null) loading.setVisibility(View.GONE);
  417 + return false;
  418 + }
  419 +
  420 + @Override
  421 + public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
  422 + if (loading != null) loading.setVisibility(View.GONE);
  423 + return false;
  424 + }
  425 + });
  426 +
  427 + rb.thumbnail(0.05f).apply(option).into(view);
  428 + }
394 429  
395 430 private static void showNoAndroidQ(Context context, int mediaType, String path, ImageView view, ProgressBar loading, RequestOptions option) {
396   - Observable.create(new ObservableOnSubscribe<String>() {
  431 + RequestBuilder rb = Glide.with(context).load(path);
  432 + rb.listener(new RequestListener() {
397 433 @Override
398   - public void subscribe(ObservableEmitter<String> emitter) throws Exception {
  434 + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
  435 + view.setScaleType(ImageView.ScaleType.CENTER);
  436 + if (loading != null) loading.setVisibility(View.GONE);
  437 + return false;
  438 + }
399 439  
400   - if (TextUtils.isEmpty(path)) {
401   - emitter.onError(new Throwable(""));
  440 + @Override
  441 + public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
  442 + if (loading != null) loading.setVisibility(View.GONE);
  443 + return false;
  444 + }
  445 + });
  446 +
  447 + rb.thumbnail(0.3f).apply(option).into(view);
  448 + }
  449 +
  450 + public static int count = 0;
  451 +
  452 + private static void showVideoThumbnail(Context context, int mediaType, long id, String path, ImageView view, ProgressBar loading, RequestOptions option) {
  453 +// Bitmap bm = getVideoThumbnail(context, id + "");
  454 +// showThumbnail(context, bm, view, loading, option);
  455 +// // 步骤1:创建被观察者 = Flowable
  456 + Flowable.create(new FlowableOnSubscribe<Bitmap>() {
  457 + @Override
  458 + public void subscribe(FlowableEmitter<Bitmap> emitter) throws Exception {
  459 + Bitmap bm = getVideoThumbnail(context, id + "");
  460 + if (bm != null) {
  461 + emitter.onNext(bm);
402 462 } else {
403   - emitter.onNext(path);
  463 + emitter.onError(new Throwable(""));
404 464 }
405 465  
  466 +// emitter.onComplete();
406 467 }
407   - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
408   - @Override
409   - public void onSubscribe(Disposable d) {
  468 + }, BackpressureStrategy.LATEST)
  469 + .subscribe(new Subscriber<Bitmap>() {
  470 + // 步骤2:创建观察者 = Subscriber & 建立订阅关系
410 471  
411   - }
  472 + @Override
  473 + public void onSubscribe(Subscription s) {
  474 +// s.request(150);
  475 + }
412 476  
413   - @Override
414   - public void onNext(String thumbnails) {
415   - RequestBuilder rb = Glide.with(context).load(thumbnails);
416   - rb.listener(new RequestListener() {
417 477 @Override
418   - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
419   - view.setScaleType(ImageView.ScaleType.CENTER);
420   - if (loading != null) loading.setVisibility(View.GONE);
421   - return false;
  478 + public void onNext(Bitmap thumbnails) {
  479 + showThumbnail(context, thumbnails, view, loading, option);
422 480 }
423 481  
424 482 @Override
425   - public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
  483 + public void onError(Throwable t) {
  484 + showNoAndroidQ(context, mediaType, path, view, loading, option);
426 485 if (loading != null) loading.setVisibility(View.GONE);
427   - return false;
428 486 }
429   - });
430   -
431   - rb.apply(option).into(view);
432   - }
433 487  
434   - @Override
435   - public void onError(Throwable e) {
436   - if (loading != null) loading.setVisibility(View.GONE);
437   - }
438   -
439   - @Override
440   - public void onComplete() {
  488 + @Override
  489 + public void onComplete() {
  490 + }
  491 + });
441 492  
442   - }
443   - });
444   - }
445 493  
446   - private static void showVideoThumbnail(Context context, int mediaType, int id, String path, ImageView view, ProgressBar loading, RequestOptions option) {
447 494 Observable.create(new ObservableOnSubscribe<Bitmap>() {
448 495 @Override
449 496 public void subscribe(ObservableEmitter<Bitmap> emitter) throws Exception {
450   - Bitmap bm = null;
451   - if (mediaType == 1) {
452   - bm = getImageThumbnail(context, id + "");
453   - emitter.onNext(bm);
454   - } else if (mediaType == 3) {
455   - bm = getVideoThumbnail(context, id + "");
456   - emitter.onNext(bm);
457   - }
  497 + count += 1;
  498 + Log.e("显示测试:", count + "");
  499 + Bitmap bitmap = getVideoThumbnail(context, id + "");
  500 + emitter.onNext(bitmap);
  501 +//
  502 +// Cursor thumbCursor = null;
  503 +// Bitmap bitmap = null;
  504 +// thumbCursor = context.getContentResolver().query(
  505 +// MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
  506 +// null, MediaStore.Video.Thumbnails.VIDEO_ID
  507 +// + "=" + id, null, null);
  508 +// if (thumbCursor.moveToFirst()) {
  509 +// String albumPath = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
  510 +// Log.e("显示测试地址:", albumPath);
  511 +// bitmap = BitmapFactory.decodeFile(albumPath);
  512 +// emitter.onNext(bitmap);
  513 +// }else {
  514 +// emitter.onNext(Bitmap.createBitmap(1,1,Bitmap.Config.RGB_565));
  515 +// }
458 516  
459 517  
460 518 }
461 519 }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {
462 520 @Override
463 521 public void onSubscribe(Disposable d) {
464   -
  522 + Log.e("显示测试:--->", "onSubscribe:" + count + "");
465 523 }
466 524  
467 525 @Override
468 526 public void onNext(Bitmap thumbnails) {
469   - if (thumbnails != null) {
470   - showThumbnail(context, thumbnails, view, loading, option);
471   - } else {
472   - showNoAndroidQ(context, mediaType, path, view, loading, option);
473   - }
  527 + Log.e("显示测试:--->", "onNext:" + count + "");
  528 + showThumbnail(context, thumbnails, view, loading, option);
474 529  
475 530 }
476 531  
477 532 @Override
478 533 public void onError(Throwable e) {
  534 + showNoAndroidQ(context, mediaType, path, view, loading, option);
479 535 if (loading != null) loading.setVisibility(View.GONE);
480 536 }
481 537  
482 538 @Override
483 539 public void onComplete() {
484   -
  540 + Log.e("显示测试:--->", "onComplete:" + count + "");
485 541 }
486 542 });
487 543 }
... ... @@ -558,6 +614,7 @@ public class GlideCacheUtil {
558 614 + "=" + videoId, null, null);
559 615 if (thumbCursor.moveToFirst()) {
560 616 String albumPath = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
  617 + Log.d("缩略图----------------->:","id:"+videoId+"地址:"+ albumPath);
561 618 bitmap = BitmapFactory.decodeFile(albumPath);
562 619 return bitmap;
563 620 }
... ...
lib_media/src/main/java/com/cnlive/media/utils/ThumbnailsUtils.java
... ... @@ -21,22 +21,21 @@ public class ThumbnailsUtils {
21 21 static HashMap<String, String> thumbnails = new HashMap<String, String>();
22 22  
23 23 public static void getThumbnails(Context context) {
24   - String[] projection = {MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.IMAGE_ID,
25   - MediaStore.Images.Thumbnails.DATA};
  24 + String[] projection = {MediaStore.Video.Thumbnails._ID, MediaStore.Video.Thumbnails.VIDEO_ID,
  25 + MediaStore.Video.Thumbnails.DATA};
26 26  
27   - Cursor cursor = context.getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null);
  27 + Cursor cursor = context.getContentResolver().query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null);
28 28 if (cursor == null) return;
29 29 while (cursor.moveToNext()) {
30 30 int _id;
31 31 int image_id;
32 32 String image_path;
33   - int _idColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);
34   - int image_idColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID);
35   - int dataColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
  33 + int _idColumn = cursor.getColumnIndex(MediaStore.Video.Thumbnails._ID);
  34 + int image_idColumn = cursor.getColumnIndex(MediaStore.Video.Thumbnails.VIDEO_ID);
  35 + int dataColumn = cursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA);
36 36 _id = cursor.getInt(_idColumn);
37 37 image_id = cursor.getInt(image_idColumn);
38 38 image_path = cursor.getString(dataColumn);
39   - Log.e("image_path:", _id+"-->"+image_id + "-->" + image_path);
40 39 thumbnails.put(image_id + "", image_path);
41 40 }
42 41  
... ...
lib_media/src/main/res/layout/activity_media_picker.xml
... ... @@ -11,6 +11,7 @@
11 11 layout="@layout/meidia_picker_actionbar_top" />
12 12  
13 13 <androidx.recyclerview.widget.RecyclerView
  14 + android:overScrollMode="never"
14 15 android:id="@+id/rv"
15 16 android:layout_above="@+id/footer"
16 17 android:layout_width="match_parent"
... ...
lib_media/src/main/res/layout/fragment_picker.xml
... ... @@ -9,6 +9,7 @@
9 9  
10 10  
11 11 <androidx.recyclerview.widget.RecyclerView
  12 + android:overScrollMode="never"
12 13 android:id="@+id/rv"
13 14 android:layout_above="@+id/footer"
14 15 android:layout_width="match_parent"
... ...
lib_media/src/main/res/layout/fragment_preview.xml
... ... @@ -8,6 +8,7 @@
8 8 android:orientation="vertical">
9 9  
10 10 <androidx.viewpager2.widget.ViewPager2
  11 + android:overScrollMode="never"
11 12 android:layout_below="@+id/top"
12 13 android:id="@+id/viewpager"
13 14 android:layout_width="match_parent"
... ...
lib_media/src/main/res/layout/media_preview_bottom_bar.xml
... ... @@ -6,6 +6,7 @@
6 6 android:background="#60000000">
7 7  
8 8 <androidx.recyclerview.widget.RecyclerView
  9 + android:overScrollMode="never"
9 10 android:id="@+id/bottom_recycler_view"
10 11 android:layout_width="match_parent"
11 12 android:layout_height="wrap_content"
... ...