JavaFX PathTransition play mp3 during animation
import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.animation.PathTransition; import javafx.animation.Timeline; import javafx.util.Duration; import javafx.scene.layout.Pane; import javafx.scene.shape.Line; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; public class Main extends Application { @Override//from w w w .j a va 2s . c om public void start(Stage primaryStage) { // Create an image ImageView image = new ImageView(new Image("http://your.gif")); // Create a media player MediaPlayer audio = new MediaPlayer(new Media("http://your.mp3")); audio.play(); // Create a line Line line = new Line(250, 600, 250, -70); // Create a pane Pane pane = new Pane(image); // Create a path transition PathTransition pt = new PathTransition(); pt.setDuration(Duration.millis(70000)); pt.setPath(line); pt.setNode(image); pt.setCycleCount(Timeline.INDEFINITE); pt.play(); // Create a scene and place it in the stage Scene scene = new Scene(pane, 500, 500); primaryStage.setTitle("java2s.com"); primaryStage.setScene(scene); primaryStage.show(); } }