RxFile is a tool class details that selects exquisite multimedia files, rxfile tool class
RxJava is already familiar to Java and android Developers. RxJava's asynchronous communication technology is favored by developers, this article introduces a multimedia tool RxFile that uses RxJava to select a mobile album.
RxFile is a tool for retrieving images or videos from Android devices. It makes it easier for you to read photos and return images, and prevents ANR. RxFile is written by a foreign name called Tournaris. This article describes how to use RxFIle.
Integration
Add the following dependencies to the jCenter () and mavenCentral () of Gradle:
Compile 'com. github. pavlospt: rxfile: 8080'
Use
1. Enable LOG
RxFile. setLoggingEnabled (true );
2. Obtain multiple files from ClipData
RxFile.createFilesFromClipData(this,clipData) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber
>() { @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
files) { Timber.e("Files list size:" + files.size()); for(File f : files){ Timber.e("onNext() file called:" + f.getAbsolutePath()); } } });
3. Use URI to access media files
RxFile.createFileFromUri(this,uri) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber
() { @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()); } });
3. Retrieve the large file Thumball through URI
I believe that Android users have a deep understanding that a file named. thumbnails will become super large over time, because it may cause the camera to be unable to take photos due to insufficient storage space, and files cannot be transmitted through Bluetooth. Sometimes we need to read this file for some operations.
''
RxFile. getThumbnail (this, data)
. SubscribeOn (Schedulers. io ())
. ObserveOn (AndroidSchedulers. mainThread ())
. Subscribe (new Subscriber (){
@ 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 );
}
});
"
More APIs
The following are some top-level callable methods provided by RXFile. You can use these methods to obtain different file formats from different channels, so that you can face the album, video selection is not a headache.
Observable getFileExtension (final String fileName );
Observable ifExists (final String path );
Observable getThumbnail (String filePath );
Observable getVideoThumbnail (final String filePath );
Observable getVideoThumbnailFromPath (final String path, final int kind );
Observable getThumbnailFromPath (String filePath );
Observable getFileType (String filePath );
Observable getPathFromUriForFileDocument (final Context context, final Uri contentUri );
Observable getPathFromUriForImageDocument (final Context context, final String mediaDocumentId );
Observable getPathFromUriForVideoDocument (final Context context, final String mediaDocumentId );
String getMimeType (String fileName );
End
RxFile is a very lightweight framework, with only 616 lines of code in Rxfile. Therefore, you do not need to worry about the excessive package size during development. It can also solve the problem of image freezing or Anr reading. The principle of RxFIle is very simple. After getting started with RxJava, you can write RxFIle on your own.