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);
}
});
此RxJava連鎖店的作品。但是我仍然在做一些錯誤的事情,因爲它滯後,並且不覺得它在後臺線程中工作。在這種情況下IO線程會做什麼以及MainThread中會做什麼?RxJava連鎖呼叫延遲
我以前用AsyncTask做過這個。它運行良好,但現在我想跳過這個,並使用RxJava來代替。我有的結果是工作,但它滯後了很多。
編輯:增加了一些更多的信息
private final PublishSubject<CreateVideoRx> mPublisher = PublishSubject.create();
上述目的是所謂的mAdapter.getPublisher()
和本身看起來像
public PublishSubject<CreateVideoRx> getPublisher() {
return mPublisher;
}
我想要做的是對提取的縮略圖功能後臺線程。然後當它完成後,我希望它被推送到一個ImageView。
可能是由於'createVideoRx'上的競爭條件;看起來像你在多個線程之間共享相同的實例,而不是發送不可變數據,比如縮略圖本身到GUI線程。 – akarnokd
你希望在io線程上完成哪些代碼塊? – yosriz
我希望我可以使第一個塊在io線程中執行。但今天早上注意到兩者都是主要執行的。 –