Java Code Examples for javafx.scene.media.MediaPlayer#setAutoPlay()

The following examples show how to use javafx.scene.media.MediaPlayer#setAutoPlay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WritePaneFrame.java    From oim-fx with MIT License 5 votes vote down vote up
void initMediaPlayer() {
	MediaPlayer mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
	mediaPlayer.setAutoPlay(true);
	PlayerPane playerPane = new PlayerPane(mediaPlayer);
	
	MediaSimplPane m=new MediaSimplPane();
	m.setUrl(MEDIA_URL);
	m.play();
	box.getChildren().add(playerPane);
	m.setStyle("-fx-background-color:rgba(230, 230, 230, 1)");
	rootPane.setCenter(m);
}
 
Example 2
Source File: Game.java    From CrazyAlpha with GNU General Public License v2.0 5 votes vote down vote up
private Game() {
    backgroundMusic = new MediaPlayer(resouceManager.getMedia("background"));
    backgroundMusic.setVolume(0.5);
    backgroundMusic.setAutoPlay(true);
    backgroundMusic.setCycleCount(MediaPlayer.INDEFINITE);
    buttonOverMusic = new MediaPlayer(resouceManager.getMedia("button_over"));
    buttonClickMusic = new MediaPlayer(resouceManager.getMedia("button_click"));
    hintMusic = new MediaPlayer(resouceManager.getMedia("hint"));
    missMusic = new MediaPlayer(resouceManager.getMedia("error2"));
}
 
Example 3
Source File: MediaTools.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static MediaPlayer play(String address, double volumn, int cycle) {
    MediaPlayer mp = new MediaPlayer(new Media(address));
    mp.setVolume(volumn);
    mp.setCycleCount(cycle);
    mp.setAutoPlay(true);
    return mp;
}
 
Example 4
Source File: StreamingMediaPlayer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public StreamingMediaPlayer() {
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    PlayerPane playerPane = new PlayerPane(mediaPlayer);
    playerPane.setMinSize(480, 360);  
    playerPane.setPrefSize(480, 360);
    playerPane.setMaxSize(480, 360);
    getStylesheets().add("ensemble/samples/media/OverlayMediaPlayer.css");
    getChildren().add(playerPane);
}
 
Example 5
Source File: OverlayMediaPlayer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public OverlayMediaPlayer() {
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    PlayerPane playerPane = new PlayerPane(mediaPlayer);
    playerPane.setMinSize(mediaWidth, mediaHeight);  
    playerPane.setPrefSize(mediaWidth, mediaHeight);
    playerPane.setMaxSize(mediaWidth, mediaHeight);
    getStylesheets().add("ensemble/samples/media/OverlayMediaPlayer.css");
    getChildren().add(playerPane);
}
 
Example 6
Source File: AdvancedMedia.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public AdvancedMedia() {
    
    
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    mediaControl = new AdvancedMedia.MediaControl(mediaPlayer);
    mediaControl.setMinSize(480,280);
    mediaControl.setPrefSize(480,280);
    mediaControl.setMaxSize(480,280);
    getChildren().add(mediaControl);
}
 
Example 7
Source File: StreamingMediaPlayer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public StreamingMediaPlayer() {
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    PlayerPane playerPane = new PlayerPane(mediaPlayer);
    playerPane.setMinSize(480, 360);  
    playerPane.setPrefSize(480, 360);
    playerPane.setMaxSize(480, 360);
    getStylesheets().add("ensemble/samples/media/OverlayMediaPlayer.css");
    getChildren().add(playerPane);
}
 
Example 8
Source File: OverlayMediaPlayer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public OverlayMediaPlayer() {
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    PlayerPane playerPane = new PlayerPane(mediaPlayer);
    playerPane.setMinSize(mediaWidth, mediaHeight);  
    playerPane.setPrefSize(mediaWidth, mediaHeight);
    playerPane.setMaxSize(mediaWidth, mediaHeight);
    getStylesheets().add("ensemble/samples/media/OverlayMediaPlayer.css");
    getChildren().add(playerPane);
}
 
Example 9
Source File: AdvancedMedia.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public AdvancedMedia() {
    
    
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    mediaControl = new AdvancedMedia.MediaControl(mediaPlayer);
    mediaControl.setMinSize(480,280);
    mediaControl.setPrefSize(480,280);
    mediaControl.setMaxSize(480,280);
    getChildren().add(mediaControl);
}
 
Example 10
Source File: AdvancedMedia.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setScene(new Scene(root));
    mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    MediaControl mediaControl = new MediaControl(mediaPlayer);
    mediaControl.setMinSize(480,280);
    mediaControl.setPrefSize(480,280);
    mediaControl.setMaxSize(480,280);
    root.getChildren().add(mediaControl);
}
 
Example 11
Source File: VideoMp4.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
private MediaPlayer getMediaPlayerFor(Media media) {
    try {
        playerReady = false;
        final MediaPlayer mediaPlayer = new MediaPlayer(media);
        if(mediaPlayer.getError() == null) {
            mediaPlayer.setAutoPlay(false);
            mediaPlayer.currentTimeProperty().addListener(new ChangeListener() {
                @Override
                public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                    Duration newDuration = (Duration) newValue;
                    progressBar.setValue((int) Math.round(newDuration.toSeconds()));
                    updateTimeLabel();
                }
            });
            mediaPlayer.setOnReady(new Runnable() {
                public void run() {
                    playerReady = true;
                    progressBar.setMinimum(0.0);
                    progressBar.setValue(0.0);
                    progressBar.setMaximum(mediaPlayer.getTotalDuration().toSeconds());
                    refreshLayout();
                }
            });
            mediaPlayer.setOnError(new Runnable() {
                public void run() {
                    processError(mediaPlayer.getError());
                }
            });
            return mediaPlayer;
        }
        else {
            processError(mediaPlayer.getError());
        }
    }
    catch(Exception e) {
        processError(e);
    }
    return null;
}
 
Example 12
Source File: MediaSimplPane.java    From oim-fx with MIT License 4 votes vote down vote up
/**
 * 设置播放视频文件地址<br>
 * http地址直接使用<br>
 * 本地视频需要用File("path").toURI().toURL().toString()
 * 
 * @author: XiaHui
 * @param url
 * @createDate: 2017年5月25日 下午6:03:14
 * @update: XiaHui
 * @updateDate: 2017年5月25日 下午6:03:14
 */
public void setUrl(String url) {
	mediaPlayer = new MediaPlayer(new Media(url));
	mediaPlayer.setAutoPlay(true);

	mediaPlayer.setCycleCount(-1);
	mediaView.setMediaPlayer(mediaPlayer);
}
 
Example 13
Source File: MediaPlayerController.java    From AudioBookConverter with GNU General Public License v2.0 4 votes vote down vote up
private void playMedias(MediaInfo selected) {
    playingTrack = selected;
    ConversionContext context = ConverterApplication.getContext();

    if (media.indexOf(selected) > media.size() - 1) return;
    timelapse.setValue(0);

    Media m = new Media(new File(selected.getFileName()).toURI().toASCIIString());
    mediaPlayer = new MediaPlayer(m);
    mediaPlayer.setAutoPlay(true);
    executorService = Executors.newSingleThreadScheduledExecutor();
    mediaPlayer.setOnReady(() -> {
        Duration duration = mediaPlayer.getMedia().getDuration();
        timelapse.setMax(duration.toSeconds());
        totalTime.setText(Utils.formatTime(duration.toMillis()));
        executorService.scheduleAtFixedRate(this::updateValues, 1, 1, TimeUnit.SECONDS);
    });

    mediaPlayer.volumeProperty().bindBidirectional(volume.valueProperty());
    mediaPlayer.volumeProperty().set(1.0);

    timelapse.valueProperty().addListener(observable -> {
        if (timelapse.isValueChanging()) {
            playTime.setText(Utils.formatTime(timelapse.getValue() * 1000));
            mediaPlayer.seek(Duration.seconds(timelapse.getValue()));
        }
    });

    mediaPlayer.setOnEndOfMedia(() -> {
        executorService.shutdown();
        mediaPlayer.volumeProperty().unbindBidirectional(volume.valueProperty());
        mediaPlayer.dispose();
        mediaPlayer = null;
        totalTime.setText("00:00:00");
        playTime.setText("00:00:00");

        MediaInfo next = findNext(selected);

        context.getSelectedMedia().clear();
        context.getSelectedMedia().add(next);

        playMedias(next);
    });
    toggleMediaPlayer();

}