Created
May 2, 2015 06:43
-
-
Save darylwong/702ef713ed74b3fbfb56 to your computer and use it in GitHub Desktop.
JavaFX media player.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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