GIF compression will happen on a background thread, but we will send updates through the GIFListener
interface, which can be applied when building the request:
GIFCompressor.into(filePath)
.setListenerHandler(handler)
.setListener(new GIFListener() {
public void onGIFCompressionProgress(double progress) {}
public void onGIFCompressionCompleted() {}
public void onGIFCompressionCanceled() {}
public void onGIFCompressionFailed(@NonNull Throwable exception) {}
})
// ...
All of the listener callbacks are called:
setListenerHandler()
compress()
callThis simply sends a double indicating the current progress. The value is typically between 0 and 1, but can be a negative value to indicate that we are not able to compute progress (yet?).
This is the right place to update a ProgressBar, for example.
The compression operation was canceled. This can happen when the Future
returned by compress()
is cancelled by the user.
This can happen in a number of cases and is typically out of our control. Input options might be wrong, write permissions might be missing, codec might be absent, input file might be not supported or simply corrupted.
You can take a look at the Throwable
being passed to know more about the exception.
Compression operation succeeded. The output file now contains the desired video.