• Tamic/Jane books original www.jianshu.com/p/eeba39f7d…

RxJava for Java and Android developers have been familiar with the technology, RxJava asynchronous communication technology is favored by developers, this article will bring a RxJava through the RxJava to select mobile phone album to obtain multimedia tool RxFile.





Tamic ‘

RxFile is a tool for retrieving images and videos from Android devices. It makes it easier for you to retrieve images from albums and prevent ANR. RxFile is written by Tournaris, and this article begins by explaining how to use RxFile.

integration

Add the following dependencies to Gradle jCenter() and mavenCentral() :

The compile ‘com. Making. Pavlospt: rxfile: 1.5’

use

1 Enable the LOG function

RxFile.setLoggingEnabled(true);

2 Get multiple files from ClipData

RxFile.createFilesFromClipData(this,clipData) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<List<File>>() { @Override public void onCompleted() { Timber.e("onCompleted() for Files called"); } @Override public void onError(Throwable e) { Timber.e("Error on files fetching:" + e.getMessage()); } @Override public void onNext(List<File> files) { Timber.e("Files list size:" + files.size()); for(File f : files){ Timber.e("onNext() file called:" + f.getAbsolutePath()); }}});Copy the code

3 Configure the media file by URI

RxFile.createFileFromUri(this,uri) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<File>() { @Override public void onCompleted() { Timber.e("onCompleted() for File called"); } @Override public void onError(Throwable e) { Timber.e("Error on file fetching:" + e.getMessage()); } @Override public void onNext(File file) { Timber.e("onNext() file called:" + file.getAbsolutePath()); }});Copy the code

Thumbnails files get really big over time because they can cause your camera to fail to take a picture due to lack of storage space or bluetooth to fail to transfer files. Sometimes we need to read this file to do something.

RxFile.getThumbnail(this,data) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<Bitmap>() { @Override public void onCompleted() { Timber.e("onCompleted() called"); } @Override public void onError(Throwable e) { Timber.e("onError called with: " + e.getMessage()); } @Override public void onNext(Bitmap bitmap) { mBitmap.setImageBitmap(bitmap); }});Copy the code

More API

Here are some of the top callable methods that RXFile provides to get different file formats from different sources, making it easier for you to face the need for photo albums and video selections.

Observable<String> getFileExtension(final String fileName);

Observable<Boolean> ifExists(final String path);

Observable<Bitmap> getThumbnail(String filePath);

Observable<Bitmap> getVideoThumbnail(final String filePath);

Observable<Bitmap> getVideoThumbnailFromPath(final String path, final int kind);

Observable<Bitmap> getThumbnailFromPath(String filePath);

Observable<String> getFileType(String filePath);

Observable<String> getPathFromUriForFileDocument(final Context context, final Uri contentUri);

Observable<String> getPathFromUriForImageDocument(final Context context, final String mediaDocumentId);

Observable<String> getPathFromUriForVideoDocument(final Context context, final String mediaDocumentId); String getMimeType(String fileName);

The end of the

RxFile is a very light framework, with only 616 lines of code, so you don’t need to worry about the package size when you develop it. It can also solve the phenomenon of stuck or Anr caused by reading pictures. RxFIle principle is very simple, basic introduction to RxJava can write their own RxFIle.

Project address: github.com/pavlospt/Rx…

More articles can be wechat search attention to my public number: developer technology front