Advertisement

Responsive Advertisement

Use Glide for gif images and gif play/pause/stop functionality

 // Load the GIF into the ImageView using Glide

Glide.with(requireContext())

        .asGif() // Indicate that you're loading a GIF

        .load(R.drawable.dice_play)

        .addListener(new RequestListener<GifDrawable>() {

            @Override

            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {

                return false;

            }


            @Override

            public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {

                resource.setLoopCount(1); // Play the GIF only once

                

                // Stop the GIF after 1 second (1000 milliseconds)

                new Handler().postDelayed(() -> {

                    resource.stop(); // Stop the GIF

                }, 1000); // Change the delay to 1000 milliseconds for 1 second

                

                return false;

            }

        })

        .into(dialogDiceRollBinding.diceLogo);


Post a Comment

0 Comments