Commit cf420cb6a35bbffcd46d015a2d772bb65b60c853
1 parent
8206d709
处理最大视频过滤
Showing
14 changed files
with
137 additions
and
87 deletions
app/src/main/java/com/cnlive/strike/debug/MainActivity.java
| @@ -71,7 +71,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | @@ -71,7 +71,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | ||
| 71 | .maxImageSize(25 * 1024 * 1024) | 71 | .maxImageSize(25 * 1024 * 1024) |
| 72 | .maxVideoSize(100*1024*1024) | 72 | .maxVideoSize(100*1024*1024) |
| 73 | .isReturnUri(AndroidQUtil.isAndroidQ()) | 73 | .isReturnUri(AndroidQUtil.isAndroidQ()) |
| 74 | - .selectMode(PickerConfig.PICKER_ONLY_ONE_TYPE) | 74 | + .selectMode(PickerConfig.PICKER_VIDEO) |
| 75 | .defaultSelectList(new ArrayList<Media>()) | 75 | .defaultSelectList(new ArrayList<Media>()) |
| 76 | .needCamera(true) | 76 | .needCamera(true) |
| 77 | .builder() | 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,7 +2,6 @@ package com.cnlive.media.frame.view; | ||
| 2 | 2 | ||
| 3 | import android.os.Build; | 3 | import android.os.Build; |
| 4 | import android.text.TextUtils; | 4 | import android.text.TextUtils; |
| 5 | -import android.util.Log; | ||
| 6 | 5 | ||
| 7 | import androidx.annotation.RequiresApi; | 6 | import androidx.annotation.RequiresApi; |
| 8 | import androidx.recyclerview.widget.GridLayoutManager; | 7 | import androidx.recyclerview.widget.GridLayoutManager; |
| @@ -12,12 +11,13 @@ import com.bumptech.glide.Glide; | @@ -12,12 +11,13 @@ import com.bumptech.glide.Glide; | ||
| 12 | import com.cnlive.libs.base.util.AlertUtil; | 11 | import com.cnlive.libs.base.util.AlertUtil; |
| 13 | import com.cnlive.libs.base.util.DoublePressed; | 12 | import com.cnlive.libs.base.util.DoublePressed; |
| 14 | import com.cnlive.media.PickerConfig; | 13 | import com.cnlive.media.PickerConfig; |
| 14 | +import com.cnlive.media.R; | ||
| 15 | import com.cnlive.media.media.entity.Folder; | 15 | import com.cnlive.media.media.entity.Folder; |
| 16 | import com.cnlive.media.media.entity.Media; | 16 | import com.cnlive.media.media.entity.Media; |
| 17 | import com.cnlive.media.ui.activity.MediaActivity; | 17 | import com.cnlive.media.ui.activity.MediaActivity; |
| 18 | -import com.cnlive.media.ui.fragment.MediaPickerFragment; | ||
| 19 | import com.cnlive.media.ui.adapter.MediaAdapter; | 18 | import com.cnlive.media.ui.adapter.MediaAdapter; |
| 20 | import com.cnlive.media.ui.adapter.OnItemClickListener; | 19 | import com.cnlive.media.ui.adapter.OnItemClickListener; |
| 20 | +import com.cnlive.media.ui.fragment.MediaPickerFragment; | ||
| 21 | import com.cnlive.media.ui.widget.SpacingDecoration; | 21 | import com.cnlive.media.ui.widget.SpacingDecoration; |
| 22 | import com.cnlive.media.utils.FileTypeUtil; | 22 | import com.cnlive.media.utils.FileTypeUtil; |
| 23 | import com.cnlive.media.utils.MediaStringUtils; | 23 | import com.cnlive.media.utils.MediaStringUtils; |
| @@ -25,11 +25,9 @@ import com.cnlive.media.utils.observable.MediaOpenActivityObservable; | @@ -25,11 +25,9 @@ import com.cnlive.media.utils.observable.MediaOpenActivityObservable; | ||
| 25 | import com.cnlive.media.utils.observable.MediaOpenInfo; | 25 | import com.cnlive.media.utils.observable.MediaOpenInfo; |
| 26 | import com.cnlive.media.utils.observable.MediaSelectStateObservable; | 26 | import com.cnlive.media.utils.observable.MediaSelectStateObservable; |
| 27 | import com.cnlive.media.utils.observable.MeidaResultObservable; | 27 | import com.cnlive.media.utils.observable.MeidaResultObservable; |
| 28 | -import com.cnlive.media.R; | ||
| 29 | import com.hannesdorfmann.mosby3.mvp.MvpView; | 28 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 30 | 29 | ||
| 31 | import java.util.ArrayList; | 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,20 +60,18 @@ public class MediaPickerFragmentView implements MvpView { | ||
| 62 | //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能 | 60 | //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能 |
| 63 | mFragment.binding.rv.setHasFixedSize(true); | 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 | mFragment.mMediaAdapter = new MediaAdapter(mFragment.getActivity(), mActivity.showTime, mActivity.mOptions); | 75 | mFragment.mMediaAdapter = new MediaAdapter(mFragment.getActivity(), mActivity.showTime, mActivity.mOptions); |
| 80 | mFragment.binding.rv.setAdapter(mFragment.mMediaAdapter); | 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,7 +60,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 60 | 60 | ||
| 61 | public void initView() { | 61 | public void initView() { |
| 62 | 62 | ||
| 63 | - Log.e("启动流程","initView"); | ||
| 64 | if (getActivity().mOptions == null) { | 63 | if (getActivity().mOptions == null) { |
| 65 | //Activity 缓存数据失效,一般情况是App被系统回收 | 64 | //Activity 缓存数据失效,一般情况是App被系统回收 |
| 66 | return; | 65 | return; |
| @@ -112,7 +111,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -112,7 +111,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 112 | videoCaceDirPath = getActivity().mOptions.getCachePath(); | 111 | videoCaceDirPath = getActivity().mOptions.getCachePath(); |
| 113 | } | 112 | } |
| 114 | } | 113 | } |
| 115 | - Log.e("启动流程","initView2"); | ||
| 116 | getActivity().mOptions.setCachePath(videoCaceDirPath); | 114 | getActivity().mOptions.setCachePath(videoCaceDirPath); |
| 117 | recordSetting.setVideoCacheDir(videoCaceDirPath); | 115 | recordSetting.setVideoCacheDir(videoCaceDirPath); |
| 118 | 116 | ||
| @@ -275,17 +273,14 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -275,17 +273,14 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 275 | 273 | ||
| 276 | @Override | 274 | @Override |
| 277 | public void onDurationTooShort() { | 275 | public void onDurationTooShort() { |
| 278 | - Log.e("", ""); | ||
| 279 | } | 276 | } |
| 280 | 277 | ||
| 281 | @Override | 278 | @Override |
| 282 | public void onRecordStarted() { | 279 | public void onRecordStarted() { |
| 283 | - Log.e("", ""); | ||
| 284 | } | 280 | } |
| 285 | 281 | ||
| 286 | @Override | 282 | @Override |
| 287 | public void onSectionRecording(long l, long l1, int i) { | 283 | public void onSectionRecording(long l, long l1, int i) { |
| 288 | - Log.e("", ""); | ||
| 289 | } | 284 | } |
| 290 | 285 | ||
| 291 | @Override | 286 | @Override |
| @@ -300,7 +295,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | @@ -300,7 +295,6 @@ public class RecordFragmentView implements MvpView, PLRecordStateListener { | ||
| 300 | 295 | ||
| 301 | @Override | 296 | @Override |
| 302 | public void onSectionDecreased(long l, long l1, int i) { | 297 | public void onSectionDecreased(long l, long l1, int i) { |
| 303 | - Log.e("", ""); | ||
| 304 | } | 298 | } |
| 305 | 299 | ||
| 306 | @Override | 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,6 +37,7 @@ public class VideoLoader extends LoaderM implements LoaderManager.LoaderCallback | ||
| 37 | MediaStore.Files.FileColumns.SIZE, | 37 | MediaStore.Files.FileColumns.SIZE, |
| 38 | MediaStore.Files.FileColumns._ID, | 38 | MediaStore.Files.FileColumns._ID, |
| 39 | MediaStore.Files.FileColumns.PARENT, | 39 | MediaStore.Files.FileColumns.PARENT, |
| 40 | + MediaStore.Video.VideoColumns._ID, | ||
| 40 | MediaStore.Video.VideoColumns.DURATION}; | 41 | MediaStore.Video.VideoColumns.DURATION}; |
| 41 | 42 | ||
| 42 | Context mContext; | 43 | Context mContext; |
lib_media/src/main/java/com/cnlive/media/ui/activity/MediaActivity.java
| @@ -191,6 +191,8 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | @@ -191,6 +191,8 @@ public class MediaActivity extends MvpBindingActivity<MediaView, MediaPresenter, | ||
| 191 | ((MediaPickerFragment) currentFragment).setMediaData(list); | 191 | ((MediaPickerFragment) currentFragment).setMediaData(list); |
| 192 | if (mFolderAdapter != null) mFolderAdapter.updateAdapter(list); | 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<RecordPreviewView, | @@ -117,7 +117,6 @@ public class RecordPreviewFragment extends MvpBindingFragment<RecordPreviewView, | ||
| 117 | startActivity(intent); | 117 | startActivity(intent); |
| 118 | } | 118 | } |
| 119 | } catch (Exception e) { | 119 | } catch (Exception e) { |
| 120 | - Log.e("异常:", e.getMessage()); | ||
| 121 | } | 120 | } |
| 122 | 121 | ||
| 123 | } else if (v.getId() == R.id.tb_cancel) { | 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,7 +189,6 @@ public class CropUtil { | ||
| 189 | System.gc(); | 189 | System.gc(); |
| 190 | resultPath = file.getAbsolutePath(); | 190 | resultPath = file.getAbsolutePath(); |
| 191 | } catch (IOException e) { | 191 | } catch (IOException e) { |
| 192 | - Log.e("CropUtils", "saveBmp(): savePath = " + savePath + "\nsaveName = " + saveName + "\n保存图片失败:" + e.toString()); | ||
| 193 | } | 192 | } |
| 194 | return resultPath; | 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,7 +1649,6 @@ public class SubsamplingScaleImageView extends View { | ||
| 1649 | return new int[]{sWidth, sHeight, exifOrientation}; | 1649 | return new int[]{sWidth, sHeight, exifOrientation}; |
| 1650 | } | 1650 | } |
| 1651 | } catch (Exception e) { | 1651 | } catch (Exception e) { |
| 1652 | - Log.e(TAG, "Failed to initialise bitmap decoder", e); | ||
| 1653 | this.exception = e; | 1652 | this.exception = e; |
| 1654 | } | 1653 | } |
| 1655 | return null; | 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,9 +34,16 @@ import com.bumptech.glide.request.target.Target; | ||
| 34 | import com.cnlive.media.media.entity.Media; | 34 | import com.cnlive.media.media.entity.Media; |
| 35 | import com.cnlive.media.R; | 35 | import com.cnlive.media.R; |
| 36 | 36 | ||
| 37 | +import org.reactivestreams.Subscriber; | ||
| 38 | +import org.reactivestreams.Subscription; | ||
| 39 | + | ||
| 37 | import java.io.File; | 40 | import java.io.File; |
| 38 | import java.math.BigDecimal; | 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 | import io.reactivex.Observable; | 47 | import io.reactivex.Observable; |
| 41 | import io.reactivex.ObservableEmitter; | 48 | import io.reactivex.ObservableEmitter; |
| 42 | import io.reactivex.ObservableOnSubscribe; | 49 | import io.reactivex.ObservableOnSubscribe; |
| @@ -322,7 +329,10 @@ public class GlideCacheUtil { | @@ -322,7 +329,10 @@ public class GlideCacheUtil { | ||
| 322 | } | 329 | } |
| 323 | if (media.mediaType == 1) { | 330 | if (media.mediaType == 1) { |
| 324 | option = option.error(R.drawable.iv_imgload_full_err); | 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 | if (AndroidQUtil.isAndroidQ()) { | 336 | if (AndroidQUtil.isAndroidQ()) { |
| 327 | showAndroidQ(context, media.mediaType, mediaUri, view, loading, option); | 337 | showAndroidQ(context, media.mediaType, mediaUri, view, loading, option); |
| 328 | } else { | 338 | } else { |
| @@ -330,8 +340,14 @@ public class GlideCacheUtil { | @@ -330,8 +340,14 @@ public class GlideCacheUtil { | ||
| 330 | showNoAndroidQ(context, media.mediaType, media.path, view, loading, option); | 340 | showNoAndroidQ(context, media.mediaType, media.path, view, loading, option); |
| 331 | // showImageThumbnail(context, media.mediaType, media.id, media.path, view, loading, option); | 341 | // showImageThumbnail(context, media.mediaType, media.id, media.path, view, loading, option); |
| 332 | } else if (media.mediaType == 3) { | 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,7 +367,7 @@ public class GlideCacheUtil { | ||
| 351 | Bitmap bm = contentResolver.loadThumbnail(mediaUri, new Size(100, 100), null); | 367 | Bitmap bm = contentResolver.loadThumbnail(mediaUri, new Size(100, 100), null); |
| 352 | emitter.onNext(bm); | 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 | @Override | 371 | @Override |
| 356 | public void onSubscribe(Disposable d) { | 372 | public void onSubscribe(Disposable d) { |
| 357 | 373 | ||
| @@ -391,97 +407,137 @@ public class GlideCacheUtil { | @@ -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 | private static void showNoAndroidQ(Context context, int mediaType, String path, ImageView view, ProgressBar loading, RequestOptions option) { | 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 | @Override | 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 | } else { | 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 | @Override | 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 | @Override | 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 | if (loading != null) loading.setVisibility(View.GONE); | 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 | Observable.create(new ObservableOnSubscribe<Bitmap>() { | 494 | Observable.create(new ObservableOnSubscribe<Bitmap>() { |
| 448 | @Override | 495 | @Override |
| 449 | public void subscribe(ObservableEmitter<Bitmap> emitter) throws Exception { | 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 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() { | 519 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() { |
| 462 | @Override | 520 | @Override |
| 463 | public void onSubscribe(Disposable d) { | 521 | public void onSubscribe(Disposable d) { |
| 464 | - | 522 | + Log.e("显示测试:--->", "onSubscribe:" + count + ""); |
| 465 | } | 523 | } |
| 466 | 524 | ||
| 467 | @Override | 525 | @Override |
| 468 | public void onNext(Bitmap thumbnails) { | 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 | @Override | 532 | @Override |
| 478 | public void onError(Throwable e) { | 533 | public void onError(Throwable e) { |
| 534 | + showNoAndroidQ(context, mediaType, path, view, loading, option); | ||
| 479 | if (loading != null) loading.setVisibility(View.GONE); | 535 | if (loading != null) loading.setVisibility(View.GONE); |
| 480 | } | 536 | } |
| 481 | 537 | ||
| 482 | @Override | 538 | @Override |
| 483 | public void onComplete() { | 539 | public void onComplete() { |
| 484 | - | 540 | + Log.e("显示测试:--->", "onComplete:" + count + ""); |
| 485 | } | 541 | } |
| 486 | }); | 542 | }); |
| 487 | } | 543 | } |
| @@ -558,6 +614,7 @@ public class GlideCacheUtil { | @@ -558,6 +614,7 @@ public class GlideCacheUtil { | ||
| 558 | + "=" + videoId, null, null); | 614 | + "=" + videoId, null, null); |
| 559 | if (thumbCursor.moveToFirst()) { | 615 | if (thumbCursor.moveToFirst()) { |
| 560 | String albumPath = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA)); | 616 | String albumPath = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA)); |
| 617 | + Log.d("缩略图----------------->:","id:"+videoId+"地址:"+ albumPath); | ||
| 561 | bitmap = BitmapFactory.decodeFile(albumPath); | 618 | bitmap = BitmapFactory.decodeFile(albumPath); |
| 562 | return bitmap; | 619 | return bitmap; |
| 563 | } | 620 | } |
lib_media/src/main/java/com/cnlive/media/utils/ThumbnailsUtils.java
| @@ -21,22 +21,21 @@ public class ThumbnailsUtils { | @@ -21,22 +21,21 @@ public class ThumbnailsUtils { | ||
| 21 | static HashMap<String, String> thumbnails = new HashMap<String, String>(); | 21 | static HashMap<String, String> thumbnails = new HashMap<String, String>(); |
| 22 | 22 | ||
| 23 | public static void getThumbnails(Context context) { | 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 | if (cursor == null) return; | 28 | if (cursor == null) return; |
| 29 | while (cursor.moveToNext()) { | 29 | while (cursor.moveToNext()) { |
| 30 | int _id; | 30 | int _id; |
| 31 | int image_id; | 31 | int image_id; |
| 32 | String image_path; | 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 | _id = cursor.getInt(_idColumn); | 36 | _id = cursor.getInt(_idColumn); |
| 37 | image_id = cursor.getInt(image_idColumn); | 37 | image_id = cursor.getInt(image_idColumn); |
| 38 | image_path = cursor.getString(dataColumn); | 38 | image_path = cursor.getString(dataColumn); |
| 39 | - Log.e("image_path:", _id+"-->"+image_id + "-->" + image_path); | ||
| 40 | thumbnails.put(image_id + "", image_path); | 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,6 +11,7 @@ | ||
| 11 | layout="@layout/meidia_picker_actionbar_top" /> | 11 | layout="@layout/meidia_picker_actionbar_top" /> |
| 12 | 12 | ||
| 13 | <androidx.recyclerview.widget.RecyclerView | 13 | <androidx.recyclerview.widget.RecyclerView |
| 14 | + android:overScrollMode="never" | ||
| 14 | android:id="@+id/rv" | 15 | android:id="@+id/rv" |
| 15 | android:layout_above="@+id/footer" | 16 | android:layout_above="@+id/footer" |
| 16 | android:layout_width="match_parent" | 17 | android:layout_width="match_parent" |
lib_media/src/main/res/layout/fragment_picker.xml
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | <androidx.recyclerview.widget.RecyclerView | 11 | <androidx.recyclerview.widget.RecyclerView |
| 12 | + android:overScrollMode="never" | ||
| 12 | android:id="@+id/rv" | 13 | android:id="@+id/rv" |
| 13 | android:layout_above="@+id/footer" | 14 | android:layout_above="@+id/footer" |
| 14 | android:layout_width="match_parent" | 15 | android:layout_width="match_parent" |
lib_media/src/main/res/layout/fragment_preview.xml
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | android:orientation="vertical"> | 8 | android:orientation="vertical"> |
| 9 | 9 | ||
| 10 | <androidx.viewpager2.widget.ViewPager2 | 10 | <androidx.viewpager2.widget.ViewPager2 |
| 11 | + android:overScrollMode="never" | ||
| 11 | android:layout_below="@+id/top" | 12 | android:layout_below="@+id/top" |
| 12 | android:id="@+id/viewpager" | 13 | android:id="@+id/viewpager" |
| 13 | android:layout_width="match_parent" | 14 | android:layout_width="match_parent" |
lib_media/src/main/res/layout/media_preview_bottom_bar.xml
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | android:background="#60000000"> | 6 | android:background="#60000000"> |
| 7 | 7 | ||
| 8 | <androidx.recyclerview.widget.RecyclerView | 8 | <androidx.recyclerview.widget.RecyclerView |
| 9 | + android:overScrollMode="never" | ||
| 9 | android:id="@+id/bottom_recycler_view" | 10 | android:id="@+id/bottom_recycler_view" |
| 10 | android:layout_width="match_parent" | 11 | android:layout_width="match_parent" |
| 11 | android:layout_height="wrap_content" | 12 | android:layout_height="wrap_content" |