Longer gif duration in ImageView

209 Views Asked by At

I'm writing a desktop application with javafx and when I add a gif to an ImageView from URL source (http) it only plays part of the gif. I've even tried downloading the gif to a file on my system and it still only played for a second. When I play it in my browser it plays fully.

How can I display a gif from giphy or any other gif hosting site into imageview to play the full duration?

 public void retrieveGif() {

    System.out.println("retreiving gif");

    giphyImage.setImage(new Image("http://i.giphy.com/E2d2tsgz7iHo4.gif"));

}
1

There are 1 best solutions below

1
On BEST ANSWER

Maybe this gif is broken.

I downloaded and resized and uploaded it works.

Resize: https://ezgif.com/resize

Upload: https://gifyu.com/

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("ImageView Experiment 1");

    String imgUrl = "https://s5.gifyu.com/images/test222466041f4e8599a.gif";
    URLConnection connection = new URL(imgUrl).openConnection();
    connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
    Image image = new Image(connection.getInputStream());
    ImageView imageView = new ImageView();
    imageView.setImage(image);

    HBox hbox = new HBox(imageView);

    Scene scene = new Scene(hbox, 200, 200);
    primaryStage.setScene(scene);
    primaryStage.show();

}

public static void main(String[] args) {
    Application.launch(args);
}