private void playCrossfade(final List<? extends Playable> items, final int index) { MediaPlayer oldPlayer = currentPlayer; final double currentVolume = oldPlayer.getVolume(); oldPlayer.volumeProperty().unbind(); playQueue = new ArrayList<>(items); currentIndex = index; MediaPlayer newPlayer = new MediaPlayer(new Media(playQueue.get(currentIndex).getUri().toString())); newPlayer.setVolume(0); newPlayer.play(); Timeline crossfade = new Timeline(new KeyFrame(Duration.seconds(CROSSFADE_DURATION), new KeyValue(oldPlayer.volumeProperty(), 0), new KeyValue(newPlayer.volumeProperty(), currentVolume))); crossfade.setOnFinished(event -> { oldPlayer.stop(); setCurrentPlayer(newPlayer); }); crossfade.play(); }
private void addBackgroundMediaView() { Media media = new Media(MovieView.class.getResource("/backdrop-video.mp4").toExternalForm()); MediaPlayer player = new MediaPlayer(media); player.setMute(true); MediaView mediaView = new MediaView(player); mediaView.setOpacity(.3); getChildren().add(mediaView); mediaView.visibleProperty().bind(getSkinnable().showMediaViewBackgroundProperty()); getSkinnable().showMediaViewBackgroundProperty().addListener(it -> { if (getSkinnable().isShowMediaViewBackground()) { /* * Implementing our own infinite loop support. * The built-in cycle count support seems to be buggy. */ player.setOnEndOfMedia(() -> { player.seek(Duration.ZERO); player.play(); }); player.play(); } else { player.stop(); } }); }
public Music(File f) { file = f; String path = StringUtil.convertToFileURL(file.toURI().getRawPath()); String url = StringUtil.convertToFileURL(file.getAbsolutePath()); String[] split = url.split("/"); String uri = url.split("/")[split.length - 1]; String[] sp = uri.split("\\."); format = new SimpleStringProperty(sp[sp.length - 1]); sp[sp.length - 1] = ""; name = new SimpleStringProperty(String.join(".", sp)); media = new MediaPlayer(new Media(path)); duration = new SimpleStringProperty(""); }
@Override public void run(Queue queue) { Thread thread = new Thread(new Runnable() { public void run() { try { Media m = new Media(new File(config.getToneBeforeDownloadPath()).toURI().toString()); MediaPlayer mp = new MediaPlayer(m); mp.play(); } catch (Exception e) { e.printStackTrace(); DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play before download sound", "---", "Error occurred when trying to play sound", false, e)); } } }); thread.setDaemon(true); thread.start(); }
@Override public void run(Queue queue) { Thread thread = new Thread(new Runnable() { public void run() { try { Media m = new Media(new File(config.getToneAfterDownloadPath()).toURI().toString()); MediaPlayer mp = new MediaPlayer(m); mp.play(); } catch (Exception e) { e.printStackTrace(); DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play after download sound", "---", "Error occurred when trying to play sound", false, e)); } } }); thread.setDaemon(true); thread.start(); }
public static void playSound(String ressource) { log.info("Try to play " + ressource); URL url = ClassLoader.getSystemResource(ressource); String path = null; if (url == null) { path = new File(ressource).toURI().toString(); } else path = url.toString(); log.info("path " + path); try { Media media = new Media(path); MediaPlayer mp = new MediaPlayer(media); mp.play(); } catch (Exception e) { log.error("Exception", e); } }
private void setCurrentPlayer(final MediaPlayer player) { currentPlayer = player; Category newItem = playQueue.get(currentIndex); switch (CategoryType.of(newItem)) { case Songs: newSongBeingPlayed(); break; case Videos: newVideoBeingPlayed(); break; } currentPlayer.setOnEndOfMedia(() -> { if (lastPlayed.size() > maxDeckSize) { lastPlayed.pollLast(); lastPlayed.addFirst(playQueue.get(currentIndex)); } currentIndex = nextIndex(); Media media = new Media(playQueue.get(currentIndex).getUri().toString()); setCurrentPlayer(new MediaPlayer(media)); currentPlayer.play(); }); currentPlayer.statusProperty() .addListener((observable, oldValue, newValue) -> playingStatusChanged(newValue)); currentPlayer.currentTimeProperty().addListener(ov -> timeUpdated()); currentPlayer.currentTimeProperty().addListener(crossfadeTimeListener()); currentPlayer.setOnReady(this::timeUpdated); currentPlayer.volumeProperty().bind(volume); }
private void playTrailer() { final Media media = model.getSelectedMovie().loadTrailer(); final MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setOnEndOfMedia(() -> { mediaPane.setVisible(false); mediaPlayer.stop(); mediaPlayer.dispose(); }); mediaView.setOnMouseClicked(e -> { if(MediaPlayer.Status.PLAYING.equals(mediaPlayer.getStatus())) { mediaPlayer.pause(); mediaStateIcon.toPlay(); } else { mediaPlayer.play(); mediaStateIcon.toPause(); } }); mediaView.setMediaPlayer(mediaPlayer); mediaPane.setVisible(true); mediaPlayer.play(); }
@Override public void start(Stage stage) { ScreensController mainContainer = new ScreensController(); mainContainer.loadScreen(screenMenuID, screenMenuFile); mainContainer.loadScreen(screenMainID, screenMainFile); mainContainer.setScreen(screenMenuID); Group root = new Group(); root.getChildren().addAll(mainContainer); Scene scene = new Scene(root, Color.TRANSPARENT); stage.setScene(scene); stage.show(); //Music Theme Himalya File filestring = new File("src/resources/music/music_menu.mp3"); Media file = new Media(filestring.toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(file); mediaPlayer.autoPlayProperty(); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); mediaPlayer.play(); }
/** * Instantiates a new model.Game. * <p> * Init szekvencia. * </p> */ public Game() { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("game.fxml")); Parent root = null; try { root = fxmlLoader.load(); } catch (IOException e) { e.printStackTrace(); return; } Controller ctrl = fxmlLoader.getController(); ctrl.setModel(this); timer = new SimulationTimer(); mapManager = new MapManager(timer, this); view = new View(mapManager, ctrl); view.setScene(new Scene(root)); timer.setView(view); winMedia = new MediaPlayer(new Media(new File(winSound).toURI().toString())); loseMedia = new MediaPlayer(new Media(new File(loseSound).toURI().toString())); }
private void loadingParam() { File paramFile = new File("res/Parameters"); Scanner sc; try { sc = new Scanner(paramFile); if (sc.hasNextLine()) { isRandom = Boolean.valueOf(sc.nextLine()); musicIndex = Integer.valueOf(sc.nextLine()); } hit = new Media(musicList.get(musicIndex).toURI().toString()); mediaPlayer = new MediaPlayer(hit); mediaPlayer.setOnReady(this::playMusic); } catch (IOException e) { e.printStackTrace(); } }
private boolean loadingFile() { File f = new File("res/MusicList"); Scanner scn; try { scn = new Scanner(f); if (!scn.hasNextLine()) return false; while (scn.hasNextLine()) { musicList.add(new File(scn.nextLine())); } } catch (FileNotFoundException e) { e.printStackTrace(); } for (int i = 0; i < musicList.size(); i++) { Media hit = new Media(musicList.get(i).toURI().toString()); String song = hit.getSource().split("/")[hit.getSource().split("/").length - 1].replace("%20", " "); listView.getItems().add(song); } listView.scrollTo(0); return true; }
/** * FE start/stop button * * @param event */ public void startBtnAction(ActionEvent event) { if (!isRecording) { countLabel.setText("Recording"); startBtn.setText("Stop"); isRecording = true; saveBtn.setVisible(false); saver = new Saver(); Media sound = new Media(this.songPath); mediaPlayer = new MediaPlayer(sound); mediaPlayer.play(); textPresses.setText(""); } else { countLabel.setText("Editor"); startBtn.setText("Start"); isRecording = false; saveBtn.setVisible(true); mediaPlayer.stop(); mediaPlayer = null; } startListenButtons(); }
public void startAction() { timer1 = null; task = null; if (currentMinutes <= 0 && currentSeconds <= 0) { currentMinutes = 10; currentSeconds = 0; } setTimer(currentMinutes, currentSeconds); media = new Media(path); mp = new MediaPlayer(media); reset.setDisable(false); stop.setDisable(false); pomodoro.setDisable(false); shortBreak.setDisable(false); longBreak.setDisable(false); volume.setDisable(false); }
public VideoPlayer(String p) { super(); this.file = new Media(p); this.player = new MediaPlayer(this.file); this.view = new MediaView(this.player); this.pane = new BorderPane(); this.fxScene = new Scene(this.pane); this.pane.setCenter(this.view); this.fxScene.setFill(Paint.valueOf("black")); this.addComponentListener(this); this.addKeyListener(this); this.componentResized(null); this.setScene(this.fxScene); }
/** * Method that contains a series of initialize statements * */ private void initialize() { myPromptFactory = new PromptFactory(); // myControl = new StandardControl(getGameRunner()); //myHUD = new StandardHUD(getGameRunner()); myStage = new Stage(); myPane = new AnchorPane(); myPane.setId("bp"); myGameScreen = new Pane(); myPrompt = new PromptFactory(); myKeyEvents = new ArrayList<>(); myBGM = new Media(new File(BGM_PATH).toURI().toString()); myMediaPlayer = new MediaPlayer(myBGM); myScreensHolder = new StackPane(); myUIScreen = new Pane(); }
public MediaPlayer loadVideo(int videoIndex) { LoggerFacade.INSTANCE.debug(this.getClass(), "Load video"); // NOI18N final StringBuilder sb = new StringBuilder(); sb.append(PREFIX__VIDEO); sb.append(videoIndex); sb.append(SUFFIX__FILE); final String video = PropertiesFacade.INSTANCE.getProperty(KEY__RESOURCE_BUNDLE__VIDEO, sb.toString()); try { final Media media = new Media(this.getClass().getResource(video).toURI().toString()); final MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); mediaPlayer.setOnReady(() -> { mediaPlayer.play(); }); return mediaPlayer; } catch (URISyntaxException ex) { LoggerFacade.INSTANCE.error(this.getClass(), "Can't load video: " + video, ex); // NOI18N } return null; }
@Override public void playSong(SongData songData) { if (songData != null && !songData.getTitle().equals(" ")) { settingsFactory.setPlayingSong(songData); this.currentPlayingSong = songData; this.stopPlaying(); try { File songFile = new File(songData.getPath()); AudioFile audioFile = AudioFileIO.read(songFile); isPlaying = true; player = new MediaPlayer(new Media(songFile.toURI().toURL().toExternalForm())); songPlayerBarController.setupForPlayingMusic(audioFile); player.play(); player.setOnEndOfMedia(this::playNextSong); } catch (Exception e) { e.printStackTrace(); } } }
private MediaManager(String[] media) { this.players = new HashMap<String, Media>(); this.images = new HashMap<String, Image>(); int changed = 0; for(String m : media) { String path = FileUtils.ResolveResource(m).toString(); String ext = FileUtils.getFileExtension(path); String name = FileUtils.getFileName(path); if(ext.equals("wav") || ext.equals("mp3")) { this.players.put(name, new Media(path)); changed++; } else if(ext.equals("png")) { this.images.put(name, new Image(path)); changed++; } } Logger.getLogger().info("MediaManager loaded! " + changed + " media resources loaded"); }
@Test public void shouldPlayTrack() { ReflectionTestUtils.setField(spyMediaManager, "cacheManager", cacheManager); when(mockTrack.getTrackId()).thenReturn("trackId"); when(mockTrack.getLocation()).thenReturn("http://www.example.com/media%2Emp3"); spyMediaManager.playTrack(mockTrack); String source = "http://localhost:" + internalJettyPort + "/cache?cacheType=TRACK&id=trackId&url=http%3A%2F%2Fwww.example.com%2Fmedia.mp3"; Media currentMedia = (Media)ReflectionTestUtils.getField(spyMediaManager, "currentMedia"); assertThat("Current media has a URI of '" + source + "'", currentMedia.getSource(), equalTo(source)); assertThat("Current track is the mock track", ReflectionTestUtils.getField(spyMediaManager, "currentTrack") == mockTrack, equalTo(true)); verify(mockMediaPlayer, times(1)).play(); verify(getMockEventManager(), times(1)).fireEvent(Event.TRACK_QUEUED_FOR_PLAYING, mockTrack); }
@Override public void start(Stage palco) throws Exception { Media media = new Media(VIDEO_URL); // 1 MediaPlayer mediaPlayer = new MediaPlayer(media); // 2 MediaView mediaView = new MediaView(mediaPlayer); // 3 StackPane raiz = new StackPane(); raiz.getChildren().add(mediaView); // 4 Scene cena = new Scene(raiz, 600, 400); palco.setTitle("Tocando Video em JavaFX"); palco.setScene(cena); palco.show(); mediaPlayer.play(); // 4 }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Video"); final List<String> args = getParameters().getRaw(); String url = args.size() > 0 ? args.get(args.size() - 1) : "http://www.mediacollege.com/" + "video-gallery/testclips/20051210-w50s.flv"; Media media = new Media(url); MediaPlayer player = new MediaPlayer(media); player.play(); MediaView view = new MediaView(player); Group root = new Group(); root.getChildren().add(view); Scene scene = SceneBuilder.create(). width(360).height(288). root(root). fill(Color.WHITE). build(); primaryStage.setScene(scene); primaryStage.show(); }
private VBox getNotificationView() { VBox vBox = new VBox(5); vBox.setId("notification"); vBox.setAlignment(Pos.CENTER); VBox.setVgrow(vBox, Priority.ALWAYS); Image alert = new Image(getClass().getResourceAsStream("/Images/Icons/alert.png")); ImageView imageView = new ImageView(alert); notificationText = new Label(""); notificationText = (Label) Styler.styleAdd(notificationText, "label-light"); vBox.getChildren().addAll(imageView, notificationText); vBox.getStylesheets().add(getClass().getResource("/css/global.css").toExternalForm()); if (MausSettings.SOUND) { Media notify = new Media(getClass().getResource("/audio/notify.mp3").toExternalForm()); MediaPlayer mediaPlayer = new MediaPlayer(notify); mediaPlayer.play(); } Styler.styleAdd(vBox, "notification"); return vBox; }
/** * Level initialisieren * * @param collector - Objektsammler */ @Override protected void init(ObjectCollector collector) { rdm = new Random(); // Init Hintergrundmusik menuTheme = new Media(getClass().getResource("/de/janroslan/verse/resources/sounds/menu.aiff").toExternalForm()); mplayer = new MediaPlayer(menuTheme); mplayer.setVolume(0.7); mplayer.setAutoPlay(true); // Init Maus Hover Sound buttonHoverSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/click.wav").toString()); initPictures(collector); initObjs(collector); initTexts(collector); initButtons(collector); }
/** * The constructor method for music, takes an ArrayList and creates the instance of the class * using the default play list * @param playlistStrings is a list of strings that music initializes with, accessing those sound files * and turning them into a play list to be played. */ public Music(List<String> playlistStrings) { persistentSettings(); playlist = new ArrayList<MediaPlayer>(); for (int i = 0; i < playlistStrings.size(); i++) { try { URL url = Music.class.getResource("../Music/" + playlistStrings.get(i)); Media media = new Media(url.toString()); MediaPlayer listPlayer = new MediaPlayer(media); playlist.add(listPlayer); } catch (RuntimeException re) { LOG.error("There was an error creating the mediaplayer, perhaps incorrect filename or it is not" + " stored in the music folder under resources", re); } } }
public void newUserNotification(Message msg) { Platform.runLater(() -> { Image profileImg = new Image(getClass().getClassLoader().getResource("images/" + msg.getPicture().toLowerCase() +".png").toString(),50,50,false,false); TrayNotification tray = new TrayNotification(); tray.setTitle("A new user has joined!"); tray.setMessage(msg.getName() + " has joined the JavaFX Chatroom!"); tray.setRectangleFill(Paint.valueOf("#2C3E50")); tray.setAnimationType(AnimationType.POPUP); tray.setImage(profileImg); tray.showAndDismiss(Duration.seconds(5)); try { Media hit = new Media(getClass().getClassLoader().getResource("sounds/notification.wav").toString()); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play(); } catch (Exception e) { e.printStackTrace(); } }); }
MusicPlayer(File f){ this.song = new Media(Paths.get(f.getAbsolutePath()).toUri().toString()); this.player = new MediaPlayer(song); while(player.getStatus() != MediaPlayer.Status.READY){ try { sleep(10); } catch (InterruptedException ex) {} } this.length = player.getTotalDuration().toSeconds(); this.state = MusicPlayerState.STOPPED; this.songName = f.getName(); this.player.setOnEndOfMedia(new Runnable() { @Override public void run() { player.stop(); state = MusicPlayerState.STOPPED; } }); }
@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("../org.csstudio.display.builder.model/examples/audio/timer.wav"); new File("../org.csstudio.display.builder.model/examples/timer/timer.mp3"); final Media audio = new Media(file.toURI().toString()); final MediaPlayer player = new MediaPlayer(audio); player.setOnEndOfMedia( () -> player.stop()); player.play(); player.setOnStopped(() -> { player.dispose(); stage.close(); }); }
public MediaRhythm(String mediaString) { Media m = new Media(mediaString); mediaPlayer = new MediaPlayer(m); mediaPlayer.pause(); beatProperty = new SimpleLongProperty(0L); isPlaying = false; startedPauseAt = 0L; timer = new AnimationTimer() { @Override public void handle(long now) { update(); } }; }
private void createScene(final String mediaUrl) { StackPane root = new StackPane(); final Scene scene = new Scene(root); final File f = new File(mediaUrl); final Media m = new Media(f.toURI().toString()); mediaPlayer = new MediaPlayer(m); final MediaView mv = new MediaView(mediaPlayer); final DoubleProperty width = mv.fitWidthProperty(); final DoubleProperty height = mv.fitHeightProperty(); width.bind(Bindings.selectDouble(mv.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mv.sceneProperty(), "height")); mv.setPreserveRatio(true); // mediaPlayer.setAutoPlay(true); // mediaPlayer.setCycleCount(Integer.MAX_VALUE); mediaPlayer.setOnEndOfMedia(new Runnable() { @Override public void run() { replay(); } }); root.getChildren().add(mv); fxContainer.setScene(scene); }
private void create(final String file) { final File soundFile = new File(file); if (!soundFile.exists()) { System.err.println("Sound File \"" + file + "\" not found!"); return; } String[] strings = file.split("/"); this.soundFile = strings[strings.length - 1]; new Thread() { public void run() { try { sound = new MediaPlayer(new Media(soundFile.toURI().toString())); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
@Override public void initComponents() { media = new Media(getClass().getResource(RESOURCES + "videos/" + mediaName).toString()); mediaPlayer = new MediaPlayer(media); mediaView = new MediaView(mediaPlayer); slideIn = new Timeline(); slideOut = new Timeline(); rightTimer = new Label(); rightTimer.setId("lbl-timer"); leftTimer = new Label(); leftTimer.setId("lbl-timer"); vbox = new VBox(5); vbox.setId("fundo-padrao"); test = new StackPane(); timeSlider = new Slider(); btnPlay = new Button(); btnPlay.setGraphic(new ImageView(imgPause)); btnPlay.setId("btn-play"); final HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER); hbox.getChildren().addAll(leftTimer, btnPlay, rightTimer); vbox.getChildren().addAll(timeSlider, hbox); getChildren().addAll(mediaView, vbox); mediaPlayer.play(); }
public static void playMusic(String fileLoc) { if (SettingsProperties.programSound == true) { try { Thread sound; sound = new Thread() { public void run() { try { Media mu = new Media(fileLoc); MediaPlayer mediaPlayer = new MediaPlayer(mu); mediaPlayer.play(); } catch (Exception e) { e.printStackTrace(); } } }; sound.start(); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("java-buddy.blogspot.com/"); Group root = new Group(); Scene scene = new Scene(root, 540, 210); // create media player Media media = new Media((arg1 != null) ? arg1 : MEDIA_URL); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); // create mediaView and add media player to the viewer MediaView mediaView = new MediaView(mediaPlayer); ((Group)scene.getRoot()).getChildren().add(mediaView); primaryStage.setScene(scene); primaryStage.show(); }
public void start(Stage primaryStage) { primaryStage.setTitle("Embedded Media Player"); Group root = new Group(); Scene scene = new Scene(root, 540, 241); // create media player Media media = new Media("D:\\Pradeep\\Funny Mails\\Magic Sand.wmv"); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); StackPane stack = new StackPane(); Text t = new Text("Subtitle.."); // t.textProperty().addChangeListener(..); // MediaControl mediaControl = new MediaControl(mediaPlayer); MediaView m =new MediaView(mediaPlayer); stack.getChildren().addAll(m, t); scene.setRoot(stack); primaryStage.setScene(scene); primaryStage.show(); }
private Media getMediaFor(String mediaLocator) { try { final Media m = new Media(mediaLocator); if(m.getError() == null) { m.setOnError(new Runnable() { public void run() { processError(m.getError()); } }); return m; } else { processError(m.getError()); } } catch(Exception e) { processError(e); } return null; }
protected void initialize() { JFrame myFrame = getFrame(); Platform.runLater(() -> { Media media = new Media(movie); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); getMediaView().setMediaPlayer(mediaPlayer); mediaPlayer.setOnReady(() -> { myFrame.setSize(media.getWidth(), media.getHeight()); }); }); myFrame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { Platform.runLater(() -> { getMediaView().setFitWidth(myFrame.getWidth()); getMediaView().setFitHeight(myFrame.getHeight()); }); } }); }
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); }