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(); } }
@Override 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(); } }
protected synchronized void updateValues() { if(!initialized) return; if (mediaPlayer.getStatus() != Status.UNKNOWN && playTime != null && timeSlider != null && volumeSlider != null) { Platform.runLater(new Runnable() { public void run() { Duration currentTime = mediaPlayer.getCurrentTime(); // current place in playback playTime.setText(formatTime(currentTime, duration)); timeSlider.setDisable(duration.isUnknown()); //disable the time slider if we do not know the movies total duration if (!timeSlider.isDisabled() && duration.greaterThan(Duration.ZERO) && !timeSlider.isValueChanging()) { timeSlider.setValue(currentTime.divide(duration).toMillis() * 100.0); updateStatus(); } if (!volumeSlider.isValueChanging()) { volumeSlider.setValue((int) Math.round(mediaPlayer.getVolume() * 100)); } } }); } }
/** * Play sound. */ protected boolean play() { double globalVolume = CuteConfig.getDouble(CuteConfig.CUTE, "GlobalVolume"); if (soundToPlay != null) { soundToPlay.setVolume(volume.get() * globalVolume); if (soundToPlay.getStatus() == Status.PLAYING) soundToPlay.stop(); soundToPlay.play(); logger.info(String.format("Playing(%.2f): %s", soundToPlay.getVolume(), Paths.get(URI.create(soundToPlay.getMedia().getSource())))); // Element might got sick on a previous iteration. Time to make it healthy again. if (elementInfo.isSick()) { elementInfo.setAsHealthy(); } return true; } else { logger.error("Can't play the sound. MediaPlayer is not defined."); return false; } }
private void syncControlPlayPause() { MediaPlayer player = playerProperty.getValue(); if (player == null) { if (controlPlayPause.isSelected()) { controlPlayPause.setSelected(false); } } else { if (player.getStatus() == Status.PLAYING) { double ct = player.getCurrentTime().toMillis(); double mt = player.getTotalDuration().toMillis(); if (ct < mt) { if (!controlPlayPause.isSelected()) { controlPlayPause.setSelected(true); } } else { if (controlPlayPause.isSelected()) { controlPlayPause.setSelected(false); } } } else { if (controlPlayPause.isSelected()) { controlPlayPause.setSelected(false); } } } }
@Override public void play() { Status status = mediaPlayer.getStatus(); if (status == Status.UNKNOWN || status == Status.HALTED) { return; } if (status == Status.PAUSED || status == Status.STOPPED || status == Status.READY) { mediaPlayer.play(); } }
@Override public void play() { Status status = fierPlayer.getStatus(); if (status == Status.UNKNOWN || status == Status.HALTED) { return; } if (status == Status.PAUSED || status == Status.STOPPED || status == Status.READY) { fierPlayer.play(); arthPlayer.play(); } }
@Override public void keyReleased(KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.VK_H: App.finished = true; return; case KeyEvent.VK_SPACE: boolean playing = this.player.getStatus().equals(Status.PLAYING); if (playing) this.player.pause(); else this.player.play(); return; case KeyEvent.VK_ENTER: boolean inter = this.player.getStatus().equals(Status.PLAYING); this.player.stop(); if (inter) this.player.play(); return; case KeyEvent.VK_A: if (this.auto) this.auto = false; else this.auto = true; this.player.setAutoPlay(this.auto); } }
public void resumeOrPauseMedia() { if (mediaPlayer != null) { status = mediaPlayer.getStatus(); if (status == Status.PLAYING) { mediaPlayer.pause(); } else if (status == Status.PAUSED) { mediaPlayer.play(); } } }
public Splash(){ this.setLayout(new BorderLayout()); final Audioa audio = new Audioa(Helbideak.splashSound); Audioa.setVolume(10); audio.play(); JLabel label = new JLabel(Helbideak.splashGif); this.add(label,BorderLayout.CENTER); label.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if (audio.getPlayer().getStatus()==Status.STOPPED){ if (e.getKeyCode() == KeyEvent.VK_ENTER) { PokéSweeperUI.getNirePokéSweeperUI().dispose(); PokéSweeperUI.getNirePokéSweeperUI().setUndecorated(false); PokeSweeper.getNirePokéSweeper().hurrengoa(1); } } } }); PokéSweeperUI.getNirePokéSweeperUI().panelaAldatu(this); label.setFocusable(true); audio.getPlayer().setOnEndOfMedia(new Runnable() { @Override public void run() { audio.getPlayer().stop(); } }); }
public boolean isPlaying() { if (currentPlayer != null) { return currentPlayer.getStatus() == Status.PLAYING; } return false; }
public boolean isPaused() { if (currentPlayer != null) { return currentPlayer.getStatus() == Status.PAUSED; } return false; }
@Test public void shouldGetIsPlaying() { when(mockMediaPlayer.getStatus()).thenReturn(Status.PLAYING); boolean result = spyMediaManager.isPlaying(); verify(mockMediaPlayer, times(1)).getStatus(); assertThat("Playing status should be true", result, equalTo(true)); }
@Test public void shouldGetIsNotPlaying() { when(mockMediaPlayer.getStatus()).thenReturn(Status.PAUSED); boolean result = spyMediaManager.isPlaying(); verify(mockMediaPlayer, times(1)).getStatus(); assertThat("Playing status should be false", result, equalTo(false)); }
@Test public void shouldNotGetIsPlayingWhenCurrentPlayerIsNull() { ReflectionTestUtils.setField(spyMediaManager, "currentPlayer", null); when(mockMediaPlayer.getStatus()).thenReturn(Status.PLAYING); boolean result = spyMediaManager.isPlaying(); verify(mockMediaPlayer, never()).getStatus(); assertThat("Playing status should be false", result, equalTo(false)); }
@Test public void shouldGetIsPaused() { when(mockMediaPlayer.getStatus()).thenReturn(Status.PAUSED); boolean result = spyMediaManager.isPaused(); verify(mockMediaPlayer, times(1)).getStatus(); assertThat("Playing status should be true", result, equalTo(true)); }
@Test public void shouldGetIsNotPaused() { when(mockMediaPlayer.getStatus()).thenReturn(Status.PLAYING); boolean result = spyMediaManager.isPaused(); verify(mockMediaPlayer, times(1)).getStatus(); assertThat("Playing status should be false", result, equalTo(false)); }
@Test public void shouldNotGetIsPausedWhenCurrentPlayerIsNull() { ReflectionTestUtils.setField(spyMediaManager, "currentPlayer", null); when(mockMediaPlayer.getStatus()).thenReturn(Status.PAUSED); boolean result = spyMediaManager.isPaused(); verify(mockMediaPlayer, never()).getStatus(); assertThat("Playing status should be false", result, equalTo(false)); }
protected void play(FileItem fileItem, Duration position, boolean sendAction) { boolean playable = assureMediaPlayer(fileItem, ()->{ if(currentPlayer != players.get(fileItem)) { stop(false); } currentPlayer = players.get(fileItem); currentPlayingItem = fileItem; playSlider.setMax(currentPlayer.getTotalDuration().toSeconds()); currentPlayer.play(); playingLabel.setText(fileItem.getFile().getName()); if(position != null) { if(currentPlayer.getStatus() == Status.PLAYING || currentPlayer.getStatus() == Status.PAUSED) { currentPlayer.seek(position); } else { currentPlayer.setOnPlaying(()->{ currentPlayer.setOnPlaying(null); currentPlayer.seek(position); }); } } if(sendAction) { PlayAction action = new PlayAction(fileItem.getFile().getName(), position); if(position == null) { action.setPosition(currentPlayer.currentTimeProperty().get()); } sendAction(PacketCode.MEDIA_ACTION, action); } playButton.getStyleClass().clear(); playButton.getStyleClass().add("pause"); }); if(!playable) { Logger.info(fileItem + " is phantom. can't play"); } }
protected void init(){ if(mediaPlayer != null && mediaPlayer.getStatus().equals(Status.PLAYING)){ return; } initMediaPlayer(); initMediaView(); initMediaBar(); initialized=true; this.requestLayout(); }
/** * Sets the volume for all sounds controlled by {@link SuperSoundManager}. * * @param volume * The new volume to set immediately for all controlled sounds. */ public static void setVolumeForAllSounds(double volume) { MediaPlayer[] snapshotOfAllSounds = allControlledSounds.toArray(new MediaPlayer[0]); for (MediaPlayer sound : snapshotOfAllSounds) { if (sound.getStatus() != Status.DISPOSED) sound.setVolume(volume); } }
/** * Stops all sounds controlled by {@link SuperSoundManager}. * * @return True, if at least one sound was stopped. False, if no sounds were playing at the * moment. */ public static boolean stopAllSounds() { MediaPlayer[] snapshotOfAllSounds = allControlledSounds.toArray(new MediaPlayer[0]); boolean atLeastOneStopped = false; for (MediaPlayer sound : snapshotOfAllSounds) { Status status = sound.getStatus(); if (status != Status.DISPOSED && status != Status.STOPPED) { sound.stop(); atLeastOneStopped = true; } } return atLeastOneStopped; }
@FXML protected void controlHead() { MediaPlayer player = playerProperty.getValue(); if (player == null) { return; } Status status = player.getStatus(); if ((status != Status.UNKNOWN) && (status != Status.DISPOSED)) { player.seek(Duration.millis(0)); } }
private boolean checkInfoOnEvent(MediaInfo info, MediaPlayer mp) { if (info != currentInfoProperty.getValue()) { log("WARNING!!! : targetInfo != current"); if ((mp != null) && (mp.getStatus() != Status.DISPOSED)) { mp.dispose(); } return false; } return true; }
/** * 播放或者暂停 */ public void playOrPause() { if(mediaPlayer!=null&&mediaPlayer.getStatus().equals(Status.PLAYING)){ mediaPlayer.pause(); }else if(mediaPlayer==null||mediaPlayer.getStatus().equals(Status.STOPPED)){ nextSong(true); }else if(mediaPlayer!=null&& mediaPlayer.getStatus().equals(Status.PAUSED)){ mediaPlayer.play(); } }
@Override public void start(Stage stage) { // Create the media source File file = new File("sample_video1.mp4"); Media media = new Media(file.toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); //mediaPlayer.setAutoPlay(true); mediaPlayer.statusProperty().addListener( new ChangeListener<Status>() { public void changed(ObservableValue ov, Status oldStatus, Status newStatus) { System.out.println(oldStatus +"->" + newStatus); } } ); Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds(); MediaView mediaView = new MediaView(mediaPlayer); mediaView.setFitWidth(350); mediaView.setFitHeight(350); Button pauseB = new Button("Pause"); pauseB.setOnAction(e -> { mediaPlayer.pause(); }); Button playB = new Button("Play"); playB.setOnAction(e -> { mediaPlayer.play(); }); Button stopB = new Button("Stop"); stopB.setOnAction(e -> { mediaPlayer.stop(); }); HBox controlsBox = new HBox(10); controlsBox.getChildren().addAll(pauseB, playB, stopB); VBox vbox = new VBox(); vbox.getChildren().addAll(mediaView, controlsBox); // Create and set the Scene. Scene scene = new Scene(vbox); stage.setScene(scene); // Name and display the Stage. stage.setTitle("Media Demo"); /*stage.setX(primaryScreenBounds.getMinX()); stage.setY(primaryScreenBounds.getMinY());*/ stage.setWidth(400); stage.setHeight(400); stage.show(); }
public void openMedia(String aMediaUri) { if (null == aMediaUri) return; closeMedia(); // Media media = new Media(aMediaUri); MediaPlayer mediaPlayer = new MediaPlayer(media); MediaView mediaView = new MediaView(); mediaView.setMediaPlayer(mediaPlayer); // mediaView.setPreserveRatio(true); mediaView.setSmooth(true); // mediaView.fitHeightProperty().bind(heightProperty()); mediaView.fitWidthProperty().bind(widthProperty()); // mediaPlayer.volumeProperty().bind(VOLUME); mediaPlayer.setOnReady(() -> { final Media mediaReady = mediaPlayer.getMedia(); if (null != mediaReady) { updateBoundsForce(); System.out.println( String.format("Open media: %s (%dx%d)", aMediaUri, mediaReady.getWidth(), mediaReady.getHeight() )); } }); mediaView.setOnMouseClicked((event) -> { final MouseButton mouseButton = event.getButton(); if (MouseButton.SECONDARY == mouseButton) { if (Status.PLAYING == mediaPlayer.getStatus()) { mediaPlayer.pause(); } else { mediaPlayer.play(); } } else if (MouseButton.PRIMARY == mouseButton) { Duration duration = media.getDuration(); Duration newPosition = duration.divide(getWidth()).multiply(event.getX()); mediaPlayer.seek(newPosition); if (Status.PLAYING != mediaPlayer.getStatus()) { mediaPlayer.play(); } } }); mediaView.setOnScroll((event) -> setVolume(getVolume() + event.getDeltaY() * getVolumeZoom())); // MEDIA_VIEW.set(mediaView); getChildren().add(mediaView); updateBoundsForce(); }
@Override public boolean isCancelled() { return player.getStatus() == Status.STOPPED; }