1

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"));

}
Marcos Echagüe
  • 547
  • 2
  • 8
  • 21
Alj1989
  • 13
  • 3
  • Does this answer your question? [Display Animated GIF](https://stackoverflow.com/questions/3660209/display-animated-gif) – noname Dec 17 '19 at 15:02
  • 1
    Maybe [this answaer](https://stackoverflow.com/questions/28183667/how-i-can-stop-an-animated-gif-in-javafx) will help you – Marcos Echagüe Dec 17 '19 at 15:08
  • Does this answer your question? [How I can stop an animated GIF in JavaFX?](https://stackoverflow.com/questions/28183667/how-i-can-stop-an-animated-gif-in-javafx). This started with how to stop a GIF, but the code covers how to split one into frames and display all the frames. – SedJ601 Dec 17 '19 at 15:08
  • None of these helped but thank you. – Alj1989 Dec 18 '19 at 06:21

1 Answers1

0

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);
}
  • Thank you for helping me make a breakthrough I found another image that was giving me problems and I resized its pixels and it plays fully as well so it has something to do with the actual size of the gif for some reason now I have to figure out how to just resize from via url link automatically. – Alj1989 Dec 23 '19 at 16:28