javafx.scene.media.MediaPlayer#play ( )源码实例Demo

下面列出了javafx.scene.media.MediaPlayer#play ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Learn-Java-12-Programming   文件: HtmlWebView.java
public void start11(Stage primaryStage) {

        Text txt1 = new Text("What a beautiful music!");
        Text txt2 = new Text("If you don't hear music, turn up the volume.");

        File f = new File("src/main/resources/jb.mp3");
        Media m = new Media(f.toURI().toString());
        MediaPlayer mp = new MediaPlayer(m);
        MediaView mv = new MediaView(mp);

        VBox vb = new VBox(txt1, txt2, mv);
        vb.setSpacing(20);
        vb.setAlignment(Pos.CENTER);
        vb.setPadding(new Insets(10, 10, 10, 10));

        Scene scene = new Scene(vb, 350, 100);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX with embedded media player");
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();

        mp.play();
    }
 
源代码2 项目: phoebus   文件: AudioDemo.java
@Override
public void start(final Stage stage)
{
    stage.setTitle("Audio Demo");
    stage.show();

    // Windows and Mac OS X support WAV and MP3
    // Linux: WAV hangs, MP3 results in MediaException for unsupported format
    final File file = new File("../model/src/main/resources/examples/timer/timer.mp3");
    final Media audio = new Media(file.toURI().toString());
    player = new MediaPlayer(audio);
    player.setOnError(() -> System.out.println("Error!"));
    player.setOnStopped(() ->
    {
        System.out.println("Stopped.");
        player.dispose();
        stage.close();
    });
    player.setOnEndOfMedia( () ->
    {
        System.out.println("Done.");
        player.stop();
    });
    // Wasn't necessary with JDK9, but is with 11 on Mac OS X
    player.setStartTime(Duration.seconds(0));
    player.play();
    System.out.println("Playing...");
}
 
源代码3 项目: Learn-Java-12-Programming   文件: HtmlWebView.java
public void start12(Stage primaryStage) {

        Text txt = new Text("What a beautiful movie!");

        File f = new File("src/main/resources/sea.mp4");
        Media m = new Media(f.toURI().toString());
        MediaPlayer mp = new MediaPlayer(m);
        MediaView mv = new MediaView(mp);
        //mv.autosize();
        //mv.preserveRatioProperty();
        //mv.setFitHeight();
        //mv.setFitWidth();
        //mv.fitWidthProperty();
        //mv.fitHeightProperty()

        VBox vb = new VBox(txt, mv);
        vb.setSpacing(20);
        vb.setAlignment(Pos.CENTER);
        vb.setPadding(new Insets(10, 10, 10, 10));

        Scene scene = new Scene(vb, 650, 400);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX with embedded media player");
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();

        mp.play();
    }
 
源代码4 项目: Learn-Java-12-Programming   文件: HtmlWebView.java
public void start13(Stage primaryStage) {

        Text txt1 = new Text("What a beautiful movie and sound!");
        Text txt2 = new Text("If you don't hear music, turn up the volume.");

        File fs = new File("src/main/resources/jb.mp3");
        Media ms = new Media(fs.toURI().toString());
        MediaPlayer mps = new MediaPlayer(ms);
        MediaView mvs = new MediaView(mps);

        File fv = new File("src/main/resources/sea.mp4");
        Media mv = new Media(fv.toURI().toString());
        MediaPlayer mpv = new MediaPlayer(mv);
        MediaView mvv = new MediaView(mpv);

        VBox vb = new VBox(txt1, txt2, mvs, mvv);
        vb.setSpacing(20);
        vb.setAlignment(Pos.CENTER);
        vb.setPadding(new Insets(10, 10, 10, 10));

        Scene scene = new Scene(vb, 650, 500);

        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX with embedded media player");
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();

        mpv.play();
        mps.play();
    }
 
源代码5 项目: phoebus   文件: JFXRepresentation.java
AudioFuture(final MediaPlayer player)
{
    this.player = player;
    // Player by default just stays in "PLAYING" state
    player.setOnEndOfMedia(() -> player.stop());
    player.play();
    logger.log(Level.INFO, "Playing " + this);
}
 
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create an image
	ImageView image = new ImageView(new Image(
		"http://cs.armstrong.edu/liang/common/image/flag6.gif"));

	// Create a media player
	MediaPlayer audio = new MediaPlayer(new Media(
		"http://cs.armstrong.edu/liang/common/audio/anthem/anthem6.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("Exercise_16_26"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
源代码7 项目: aurous-app   文件: MediaPlayerScene.java
public Scene createScene(final String sourceURL) throws Throwable {

		final Group root = new Group();
		root.autosize();
		MediaUtils.activeMedia = sourceURL;
		final String trailer = MediaUtils.getMediaURL(sourceURL);

		media = new Media(trailer);

		player = new MediaPlayer(media);

		view = new MediaView(player);
		view.setFitWidth(1);
		view.setFitHeight(1);
		view.setPreserveRatio(false);

		// System.out.println("media.width: "+media.getWidth());

		final Scene scene = new Scene(root, 1, 1, Color.BLACK);

		player.play();

		player.setOnReady(() -> {
			ControlPanel.seek().setValue(0);

		});
		player.currentTimeProperty().addListener(
				(observableValue, duration, current) -> {

					final long currentTime = (long) current.toMillis();

					final long totalDuration = (long) player.getMedia()
							.getDuration().toMillis();
					updateTime(currentTime, totalDuration);

				});

		// PlayerUtils.activeYoutubeVideo = youtubeVideo;
		if (sourceURL.equals("https://www.youtube.com/watch?v=kGubD7KG9FQ")) {
			player.pause();
		}

		UISession.setMediaPlayer(player);
		UISession.setMediaView(view);
		UISession.setMedia(media);

		return (scene);
	}
 
 同类方法