Skip to content

Instantly share code, notes, and snippets.

@darylwong
Created May 2, 2015 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darylwong/702ef713ed74b3fbfb56 to your computer and use it in GitHub Desktop.
Save darylwong/702ef713ed74b3fbfb56 to your computer and use it in GitHub Desktop.
JavaFX media player.
package mediaplay;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class MediaPlay extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
String path = "http://www.noiseaddicts.com/samples/13.mp3";
Media media = new Media(path);
StackPane root = new StackPane();
MediaPlayer mp = new MediaPlayer(media);
mp.setAutoPlay(true);
MediaView mv = new MediaView(mp);
Label lb = new Label("Playing");
lb.setFont(Font.font("Times New Roman", 52));
lb.setTextFill(Color.BLUE);
BorderPane pane = new BorderPane();
pane.setCenter(lb);
root.getChildren().addAll(mv, pane);
Scene scene = new Scene(root, 400, 400);
stage.setScene(scene);
stage.show();
mp.play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment