JavaFX AudioClip play mp3 file during animation

Description

JavaFX AudioClip play mp3 file during animation

import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.media.AudioClip;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main extends Application {

   Pane pane = new Pane();

   @Override//w w w . java  2s.  co m
   public void start(Stage primaryStage) throws Exception {

      AudioClip audioClip = new AudioClip("file://us.mp3");
      ImageView imgView = new ImageView(new Image("/image/us.gif"));
      pane.getChildren().addAll(imgView);
      PathTransition pathT = new PathTransition(Duration.seconds(20), new Line(75, 300, 320, 75), imgView);
      pathT.play();
      audioClip.play();

      primaryStage.setScene(new Scene(pane, 400, 400));
      primaryStage.setTitle("Pane");
      primaryStage.show();
   }

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



PreviousNext

Related