private void playAudio(Media media) { if (mediaView.isVisible() == true) { mediaView.setVisible(false); display.setVisible(true); } if (mp != null) { mp.dispose(); } mp = new MediaPlayer(media); mp.play(); mp.setAudioSpectrumListener( (double timestamp, double duration1, float[] magnitudes, float[] phases) -> { display.getChildren().clear(); int i = 0; int x = 10; double y = root.getScene().getHeight() / 2; Random rand = new Random(System.currentTimeMillis()); for (float phase : phases) { int red = rand.nextInt(255); int green = rand.nextInt(255); int blue = rand.nextInt(255); Circle circle = new Circle(10); circle.setCenterX(x + i); circle.setCenterY(y + (phase * 100)); circle.setFill(Color.rgb(red, green, blue, .70)); display.getChildren().add(circle); i += 10; } }); }
@FXML private void Play(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { if (j == 0) { listView.getSelectionModel().select(j); listView.getFocusModel().focus(j); } if (mp != null) { MediaPlayer.Status status = mp.getStatus(); if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) { return; } if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.READY || status == MediaPlayer.Status.STOPPED) { if (atEndOfMedia) { atEndOfMedia = false; } onPlay(); mp.play(); statusDisplay.toBack(); play = true; } else { mp.pause(); statusDisplay.toFront(); play = false; } } } }
public void PlaySound(String soundFileName) { if (soundIsOn) { Media sound = new Media(new File(soundFileName).toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(sound); mediaPlayer.play(); } }
void stop(Runnable callback) { if (player != null) { new Tween(player.getVolume()) .tweenToZero( 0.06, 10L, (curVolume) -> { player.setVolume(curVolume); }, (zeroVolume) -> { isPlaying = false; try { if (currentAudioIn != null) { currentAudioIn.close(); } player.stop(); callback.run(); } catch (IOException | IllegalStateException | NullPointerException ex) { log.log(Level.ERROR, null, ex); } }); } else { callback.run(); } }
private void playVideo(Media media) { timeProgress.setTextFill(Color.WHITE); npView.setVisible(true); mView.toBack(); btnPaFull.setImage(new Image("icon/Full_button/full.png")); go = true; if (mediaView.isVisible() == false) { mediaView.setVisible(true); display.setVisible(false); } if (mp != null) { mp.dispose(); } mp = new MediaPlayer(media); mediaView.setMediaPlayer(mp); mediaView.setPreserveRatio(true); final DoubleProperty width = mediaView.fitWidthProperty(); final DoubleProperty height = mediaView.fitHeightProperty(); width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height")); mp.play(); }
/* * Function to set the cycle count of the MediaPlayer * * @param loop Whether the media should loop or not */ public void setLoop(boolean loop) { if (loop) { // Set to play indefinitely if loop is true mp.setCycleCount(MediaPlayer.INDEFINITE); } else { // Otherwise only play it once mp.setCycleCount(1); } }
@Override public void mute() { try { savedVolume = myMusician.getVolume(); myMusician.setVolume(MUTED); } catch (Exception e) { /* does nothing if myMusician is not initialized */ } }
@FXML private void handleProgress(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { if (play = true) { mp.seek( Duration.seconds((mp.getTotalDuration().toSeconds() * timeSlider.getValue() / 100))); } } }
@FXML void seek(MouseEvent evt) { if (player != null) { Duration d = player.getMedia().getDuration(); double millis = (evt.getX() / loadProgressBar.getWidth()) * d.toMillis(); Duration s = new Duration(millis); player.seek(s); } }
@Override public void start(Stage primaryStage) throws MalformedURLException { initialize(); primaryStage.setTitle("Media Player"); Group root = new Group(); Scene scene = new Scene(root, 540, 241); // create media player File file = new File(MEDIA_URL); Media media = null; try { if (file.exists()) { System.out.println("FILE EXISTS"); media = new Media(file.toURI().toURL().toExternalForm()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(false); MediaControl mediaControl = new MediaControl(mediaPlayer); scene.setRoot(mediaControl); primaryStage.setScene(scene); primaryStage.show(); } else { Dialogs.showErrorDialog( null, null, "Instrumental file not found. Please contact the administrator.", "ERROR"); } } catch (Exception e) { System.out.println("FILE DOES NOT EXIST"); // FileChooser fileChooser = new FileChooser(); // Set extension filter // FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("MP3 files // (*.mp3)", "*.mp3"); // fileChooser.getExtensionFilters().add(extFilter); // Show open file dialog // file = fileChooser.showOpenDialog(null); // String url = // "http://mp3crow.mobi/dl/aHR0cDovL2FwaS5zb3VuZGNsb3VkLmNvbS90cmFja3MvNjg4ODI2OTUvc3RyZWFtP2NsaWVudF9pZD1mZmEwYzc5YmY4YWVkYzBkOWIwYmIwNzQyNzhjZjI1MQ==yFRzUi1GcmVzaCAmIFNjcmF0Y2gtRCBvZiBEeW5hbWl4IElJIC0gUm9ja2luIHRvIHRoZSBCZWF0IHRoYXQgaXMgc28gRnJlc2hoaGhoaGho.mp3"; // media = new Media(file.toURI().toURL().toExternalForm()); // MediaPlayer mediaPlayer = new MediaPlayer(media); // mediaPlayer.setAutoPlay(false); // MediaControl mediaControl = new MediaControl(mediaPlayer); // scene.setRoot(mediaControl); String content = open(); root.getChildren().add(new Button(content)); primaryStage.setScene(scene); primaryStage.show(); // Dialogs.showErrorDialog(null, null, "Instrumental file not found. Please contact the // administrator.", "ERROR"); } }
public void openAndSeek(PagedList<PagedListEntry> list, int i, double s) { // if track is already playing, just seek if (list.get(i) == currentTrack) { seek(new Duration(player.getTotalDuration().toMillis() * s)); } else { open(list, i); // wait for the player to load the meta data player.setOnPlaying(() -> seek(new Duration(player.getTotalDuration().toMillis() * s))); } }
public void play() { Status status = mediaPlayer.getStatus(); if (status == Status.UNKNOWN || status == Status.HALTED) { // System.out.println("Player is in a bad or unknown state, can't play."); return; } if (status == Status.PAUSED || status == Status.STOPPED || status == Status.READY) { mediaPlayer.play(); } }
private static void playMp3(String name, boolean loop, double volume) { new javafx.embed.swing.JFXPanel(); String uriString = new File(path + name).toURI().toString(); MediaPlayer mp = new MediaPlayer(new Media(uriString)); if (loop) { mp.setCycleCount(INDEFINITE); } mp.setVolume(volume); mp.play(); mp3Map.put(name, mp); }
@FXML private void Stop(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { if (mp != null) { mp.stop(); playButton.setImage(new Image("icon/PlayPause_button/play.png")); mp.seek(mp.getStartTime()); play = false; } } }
private void stopGame() { timeline.pause(); done = true; sp.setOnMouseClicked( e -> { timeline.play(); done = false; mediaPlayer.stop(); mediaPlayer.play(); sp.setOnMouseClicked(null); }); }
@Override public void start(final Stage primaryStage) { Start.create(); menu = false; playTurn = false; URL u = getClass().getResource("start.mp3"); bgm = new MediaPlayer(new Media(u.toString())); bgm.setCycleCount(MediaPlayer.INDEFINITE); bgm.play(); root = new Group(); Image title = new Image("fantasytactics/images/title.png", 720, 600, false, false); ImageView view = new ImageView(title); Image cursor = new Image("fantasytactics/images/cursor.png"); final ImageView point = new ImageView(cursor); point.setX(165); point.setY(420); root.getChildren().add(view); root.getChildren().add(point); scene = new Scene(root, 720, 600); scene.setOnKeyPressed( new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent e) { switch (e.getCode()) { case DOWN: if (point.getY() == 420) { point.setY(460); } break; case UP: if (point.getY() == 460) { point.setY(420); } break; case ENTER: if (point.getY() == 420) { newGame(primaryStage); } else if (point.getY() == 460) { if (loadGame(primaryStage)) { missionSelectPane(primaryStage); } else { } } } } }); primaryStage.setTitle("Fantasy Tactics"); primaryStage.setScene(scene); primaryStage.show(); }
private void check() { if (checkTile(0) == true && checkTile(1) == true && checkTile(2) == true && checkTile(3) == true && checkTile(4) == true && checkTile(5) == true && checkTile(6) == true && checkTile(7) == true && checkTile(8) == true && checkTile(9) == true && checkTile(10) == true && checkTile(11) == true && checkTile(12) == true && checkTile(13) == true && checkTile(14) == true) { done = true; } if (done == true && timer != 0) { timeline.stop(); mv.setText("YOU WON !!!!!!!! IN :" + moves + " Moves"); lvl.setText("Level : " + level); iv[15].setViewport(rct[16]); sp.setText("Next"); mediaPlayer.stop(); songName = new TextField("w.mp3"); songPath = "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\"; MiniMP3Player(); mediaPlayer.play(); level++; sp.setOnAction( e -> { mediaPlayer.stop(); songName = new TextField("s.mp3"); songPath = "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\"; MiniMP3Player(); mediaPlayer.stop(); mediaPlayer.play(); nextGame(); }); } if (timer == 0) { lvl.setText("Level : " + level); mv.setText("Sorry You Loose, Time out!!"); } lvl.setText("Level : " + level); hc.setText("Your Score : " + ((level * 10) - 10) + " HS : " + getHS()); setHS(); }
@FXML private void setVolume(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { if (play = true) { if (mute == false) { mp.setVolume(0.0); mute = true; } else { mp.setVolume(1.0); mute = false; } } } }
@Override public void play() { if (player != null) { if (isPlaying) { player.pause(); isPlaying = false; log.log(LogType.PLAYER, "Pause"); } else { player.play(); isPlaying = true; log.log(LogType.PLAYER, "Play"); } UIManager.setPlayPauseIcon(isPlaying); } }
void updatePlayProgress() { if (player != null && Tray.stage.isShowing()) { Duration d = player.getMedia().getDuration(); Duration t = player.getCurrentTime(); loadProgressBar.setProgress(t.toMillis() / d.toMillis()); timeUpdate++; if (timeUpdate == 10) { timeUpdate = 0; Platform.runLater( () -> { timeLabel.setText(formatTime(d, t)); }); } } }
@Override public void pauseAudio() { try { myMusician.pause(); } catch (Exception e) { /* does nothing if myMusician is not initialized */ } }
public void start() { movie = new MediaPlayer(path); movie.play(); VIEW.setMediaPlayer(movie); movie .currentTimeProperty() .addListener( new ChangeListener<javafx.util.Duration>() { @Override public void changed( ObservableValue<? extends javafx.util.Duration> observable, javafx.util.Duration duration, javafx.util.Duration current) { timeSlider.setValue(current.toSeconds()); } }); movie.setOnReady( new Runnable() { @Override public void run() { timeSlider.setMin(0); timeSlider.setValue(0.0); timeSlider.setMax(movie.getTotalDuration().toSeconds()); volumeSlider.setMin(0); volumeSlider.setValue(0.5); } }); timeSlider.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { movie.seek(javafx.util.Duration.seconds(timeSlider.getValue())); } }); volumeSlider .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable observable) { if (volumeSlider.isValueChanging()) { movie.setVolume(volumeSlider.getValue() / 100); } } }); }
void pause(Runnable callback) { if (player != null) { new Tween(player.getVolume()) .tweenToZero( 0.06, 10L, (curVolume) -> { player.setVolume(curVolume); }, (zeroVolume) -> { player.pause(); callback.run(); }); isPlaying = false; } else { callback.run(); } }
void decreaseVolume() { if (player == null) return; double newVolume = Settings.currentVolume - 0.05; if (newVolume < 0.0) newVolume = 0.0; Settings.currentVolume = newVolume; player.setVolume(newVolume); volumeSlider.setValue(newVolume); }
@FXML private void Close(ActionEvent event) { if (mp != null) { mp.dispose(); progressBar.setProgress(0); timeSlider.setValue(0.0); timeProgress.setText("00:00/00:00"); } }
private void iniGame() { getImage(); moves = 0; ep = 15; for (int i = 0; i < 16; i++) { iv[i] = new ImageView(IMAGE); iv[i].setViewport(rct[i]); gpane.add(iv[i], i % 4, i / 4); String a = "" + i; iv[i].setId(a); } iv[15].setViewport(rct[16]); exit.setOnMouseClicked( e -> { System.out.println("Exit Successful"); System.exit(1); }); sp.setText("Start"); sp.setOnMouseClicked( e -> { if (done != true) { iv[15].setViewport(rct[15]); randomPic(); gameTimer(); startClick(); songName = new TextField("s.mp3"); songPath = "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\"; MiniMP3Player(); mediaPlayer.stop(); mediaPlayer.play(); sp.setOnMouseClicked(null); } }); stop.setOnMouseClicked( e -> { stopGame(); mediaPlayer.pause(); }); }
@FXML private void Repeat(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { repeat++; switch (repeat) { case 1: mp.setCycleCount(MediaPlayer.INDEFINITE); repeatButton.setImage(new Image("icon/Replay_button/replay_one.png")); break; case 2: mp.setCycleCount(0); repeatButton.setImage(new Image("icon/Replay_button/replay_all.png")); break; case 3: repeat = 0; repeatButton.setImage(new Image("icon/Replay_button/replay.png")); break; } } }
@FXML private void deleteList(ActionEvent event) { if (mp != null) { mp.dispose(); } if (!fileList.isEmpty() || !listName.isEmpty()) { fileList.clear(); listName.clear(); listView.setItems(listName); } }
public void open(PagedListEntry entry) { try { if (MediaManager.canPlayProtocol("https")) BackgroundLoader.addTaskWithTimeout( () -> { if (entry instanceof PlayList) { // expand inner playlists currentPlaylist.remove(entry); PagedList<PagedListEntry> innerPlaylist = ((PlayList) entry).getTrackList(); currentPlaylist.addAll(playlistPosition, innerPlaylist); currentTrack = (Track) currentPlaylist.get(++playlistPosition); } else { currentTrack = (Track) entry; } String url = currentTrack.getStreamURL(); currentMedia = new Media(url); stop(); currentTrack.getWaveform().resetProgress(); player = new MediaPlayer(currentMedia); player.volumeProperty().bindBidirectional(volumeSliderProb); player.setOnEndOfMedia(this::next); // TODO: append listener to new player player.setAudioSpectrumListener(audioSpectrumListener); player.play(); isPlaying = true; UIManager.setTrackForPlayerUI(currentTrack, currentPlaylist); UIManager.setPlayPauseIcon(isPlaying); }, 3 * 1000); } catch (NoSuchMethodError error) { // the support came together with that method String version = com.sun.javafx.runtime.VersionInfo.getRuntimeVersion(); log.log(LogType.PLAYER, "JavaFx version does not support https protocol"); log.log(LogType.PLAYER, "Min version = 8.0.72. Current version " + version); } }
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); }