Fresco: Need the way to prefetch image with progress and listener

Created on 16 Nov 2015  路  6Comments  路  Source: facebook/fresco

I was trying to use ImagePipeline's "prefetch" feature. But it accepts ImageRequest only, but ImageRequest does not have any progress or complete listeners.

I have also tried to use temp SimpleDraweeView in order to set hierarchy with ProgressDrawable and Controller with listener - but it does not download image on "setController()". I guess it start downloading only when it is rendered on the screen.

Could you please let me know how can I listen to the progress on "prefetch" OR how can I force downloading image into SimpleDraweeView created in code (without showing it on the screen).

Most helpful comment

Hello,

If you prefetchDataSource - ImagePipeline.prefetchToDiskCache(), you may (also) use onProgressUpdate() - http://frescolib.org/javadoc/reference/com/facebook/datasource/BaseDataSubscriber.html - that's including : download + eventually transcode to jpeg if you download webp pictures with one Android that can't handle them natively.

On single image request/display, you may (also) use BaseControllerListener() - http://frescolib.org/javadoc/reference/com/facebook/drawee/controller/BaseControllerListener.html - http://frescolib.org/docs/listening-download-events.html.
So you may check quality, or time to download/transcode ... until displayed ...

And finally the @lambdapioneer solution.

@xiadeye

how to use ImagePipelineConfig to listen to downloads. When setting requestListeners when initialising fresco,

This will enable listener on all ImagePipeline request and will be some logs only if FLog.setMinimumLoggingLevel(FLog.VERBOSE);

Set<RequestListener> requestListeners = new HashSet<>(); RequestLoggingListener requestLoggingListener = new RequestLoggingListener(); requestListeners.add(requestLoggingListener);

This include download, write to cache, get in cache ... transcode, , display ... events ... all events from get picture to display it with each step. http://frescolib.org/docs/troubleshooting.html.

You should set your own listener too (on all request) :
RequestListener mRequestListener = new RequestListener() {
(...)
}
http://frescolib.org/javadoc/reference/com/facebook/imagepipeline/listener/RequestListener.html
Set<RequestListener> requestListeners = new HashSet<>();
requestListeners.add(mRequestListener);

Thanks,

Eric

All 6 comments

@IanChilds I am not able to understand how to use ImagePipelineConfig to listen to downloads. When setting requestListeners when initialising fresco, how would I use the listeners later to listen to particular request? A small piece of code would be appreciated. Thanks.

same question.
Ps, @IanChilds L402-L405 is the setting code?Maybe the code has changed,could you post the function name,Tks.

@xiadeye its com.facebook.imagepipeline.core.ImagePipelineConfig.Builder#setRequestListeners

Hi @xiadeye, besides the global listener that @korniltsev suggested, you can now (v0.14+) also register listener for single image requests: ImageRequestBuilder#setRequestListener.

Usually, you want to use the former for implementing general logging and the later if you want to instrument special requests.

Hello,

If you prefetchDataSource - ImagePipeline.prefetchToDiskCache(), you may (also) use onProgressUpdate() - http://frescolib.org/javadoc/reference/com/facebook/datasource/BaseDataSubscriber.html - that's including : download + eventually transcode to jpeg if you download webp pictures with one Android that can't handle them natively.

On single image request/display, you may (also) use BaseControllerListener() - http://frescolib.org/javadoc/reference/com/facebook/drawee/controller/BaseControllerListener.html - http://frescolib.org/docs/listening-download-events.html.
So you may check quality, or time to download/transcode ... until displayed ...

And finally the @lambdapioneer solution.

@xiadeye

how to use ImagePipelineConfig to listen to downloads. When setting requestListeners when initialising fresco,

This will enable listener on all ImagePipeline request and will be some logs only if FLog.setMinimumLoggingLevel(FLog.VERBOSE);

Set<RequestListener> requestListeners = new HashSet<>(); RequestLoggingListener requestLoggingListener = new RequestLoggingListener(); requestListeners.add(requestLoggingListener);

This include download, write to cache, get in cache ... transcode, , display ... events ... all events from get picture to display it with each step. http://frescolib.org/docs/troubleshooting.html.

You should set your own listener too (on all request) :
RequestListener mRequestListener = new RequestListener() {
(...)
}
http://frescolib.org/javadoc/reference/com/facebook/imagepipeline/listener/RequestListener.html
Set<RequestListener> requestListeners = new HashSet<>();
requestListeners.add(mRequestListener);

Thanks,

Eric

Was this page helpful?
0 / 5 - 0 ratings