mDisposable = mAdapter.getPublisher()
.subscribeOn(Schedulers.io())
.map(new Function<CreateVideoRx, CreateVideoRx>() {
@Override
public CreateVideoRx apply(CreateVideoRx createVideoRx) throws Exception {
Bitmap bitmap = mMediaMetadataRetriever.getFrameAtTime(createVideoRx.time * 1000000, MediaMetadataRetriever.OPTION_CLOSEST);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, 50, 90);
createVideoRx.mBitmap = bitmap;
return createVideoRx;
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<CreateVideoRx>() {
@Override
public void accept(CreateVideoRx createVideoRx) throws Exception {
createVideoRx.mImageView.setImageBitmap(createVideoRx.mBitmap);
}
});
This RxJava chain works. But I am still doing something wrong because it lags and it does not feel like it is working on a background thread. What will be done in the IO thread in this case and what will be done in the MainThread?
I have done this before with an AsyncTask. It worked fine but now I wanted to skip that and use RxJava instead. The result I have is working but it lags a lot.
Edit: Added some more information
private final PublishSubject<CreateVideoRx> mPublisher = PublishSubject.create();
Above object is called in the mAdapter.getPublisher() and the function itself looks like
public PublishSubject<CreateVideoRx> getPublisher() {
return mPublisher;
}
What i want to do is to Extract a thumbnail on the background thread. Then when it is done i want it to be pushed to a single ImageView.
createVideoRx; looks like you share the same instance between multiple threads instead of sending immutable data, like the thumbnail itself to the GUI thread. - akarnokdmAdapter.getPublisher()? - Divers