javafx.scene.media.Media Java Examples
The following examples show how to use
javafx.scene.media.Media.
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: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 9 votes |
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(); }
Example #2
Source File: MediaPlayerController.java From MyBox with Apache License 2.0 | 8 votes |
public MediaPlayerController() { baseTitle = AppVariables.message("MediaPlayer"); SourceFileType = VisitHistory.FileType.Media; SourcePathType = VisitHistory.FileType.Media; TargetPathType = VisitHistory.FileType.Media; TargetFileType = VisitHistory.FileType.Media; AddFileType = VisitHistory.FileType.Media; AddPathType = VisitHistory.FileType.Media; targetPathKey = "MediaFilePath"; sourcePathKey = "MediaFilePath"; sourceExtensionFilter = CommonFxValues.JdkMediaExtensionFilter; targetExtensionFilter = sourceExtensionFilter; }
Example #3
Source File: VideoMp4.java From wandora with GNU General Public License v3.0 | 6 votes |
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; }
Example #4
Source File: Sound.java From Cherno with GNU General Public License v3.0 | 6 votes |
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(); }
Example #5
Source File: ChatController.java From JavaFX-Chat with GNU General Public License v3.0 | 6 votes |
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(); } }); }
Example #6
Source File: PlayerController.java From Simple-Media-Player with MIT License | 6 votes |
public void start(String url,boolean popup,int width,int height){ this.url = url; this.popup = popup; //MediaView设置 media = new Media(url); mediaPlayer = new MediaPlayer(media); mediaView.setMediaPlayer(mediaPlayer); //设置播放器,在媒体资源加载完毕后,获取相应的数据,设置组件自适应布局 setMediaPlayer(width,height); //设置各组件动作事件 setMediaViewOnClick(); setPlayButton(); setStopButton(); setVolumeButton(); setVolumeSD(); setProcessSlider(); setMaximizeButton(); }
Example #7
Source File: AudioDemo.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@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..."); }
Example #8
Source File: WritePaneFrame.java From oim-fx with MIT License | 5 votes |
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 #9
Source File: VideoMp4.java From wandora with GNU General Public License v3.0 | 5 votes |
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 #10
Source File: Exercise_16_26.java From Intro-to-Java-Programming with MIT License | 5 votes |
@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 }
Example #11
Source File: VideoView.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
public void setVideoURI(Uri uri) { System.out.println(uri.uri); Platform.runLater(new Runnable() { @Override public void run() { Media media = new Media(uri.uri); mediaPlayer = new MediaPlayer(media); mediaView.setMediaPlayer(mediaPlayer); mediaPlayer.setAutoPlay(true); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); } }); }
Example #12
Source File: VideoView.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
public void setVideoURI(Uri uri) { System.out.println(uri.uri); Platform.runLater(new Runnable() { @Override public void run() { Media media = new Media(uri.uri); mediaPlayer = new MediaPlayer(media); mediaView.setMediaPlayer(mediaPlayer); mediaPlayer.setAutoPlay(true); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); } }); }
Example #13
Source File: AdvancedMedia.java From netbeans with Apache License 2.0 | 5 votes |
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 #14
Source File: AdvancedMedia.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #15
Source File: OverlayMediaPlayer.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #16
Source File: StreamingMediaPlayer.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #17
Source File: AdvancedMedia.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #18
Source File: OverlayMediaPlayer.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #19
Source File: StreamingMediaPlayer.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #20
Source File: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 5 votes |
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(); }
Example #21
Source File: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 5 votes |
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(); }
Example #22
Source File: MediaTools.java From MyBox with Apache License 2.0 | 5 votes |
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 #23
Source File: MediaTableController.java From MyBox with Apache License 2.0 | 5 votes |
public MediaTableController() { SourceFileType = VisitHistory.FileType.Media; SourcePathType = VisitHistory.FileType.Media; TargetPathType = VisitHistory.FileType.Media; TargetFileType = VisitHistory.FileType.Media; AddFileType = VisitHistory.FileType.Media; AddPathType = VisitHistory.FileType.Media; sourceExtensionFilter = CommonFxValues.JdkMediaExtensionFilter; targetExtensionFilter = sourceExtensionFilter; }
Example #24
Source File: MediaPlayerController.java From AudioBookConverter with GNU General Public License v2.0 | 4 votes |
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(); }
Example #25
Source File: Exercise_16_23.java From Intro-to-Java-Programming with MIT License | 4 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { final int COLUMN_COUNT = 27; tfSpeed.setPrefColumnCount(COLUMN_COUNT); tfPrefix.setPrefColumnCount(COLUMN_COUNT); tfNumberOfImages.setPrefColumnCount(COLUMN_COUNT); tfURL.setPrefColumnCount(COLUMN_COUNT); // Create a button Button btStart = new Button("Start Animation"); // Create a grid pane for labels and text fields GridPane paneForInfo = new GridPane(); paneForInfo.setAlignment(Pos.CENTER); paneForInfo.add(new Label("Enter information for animation"), 0, 0); paneForInfo.add(new Label("Animation speed in milliseconds"), 0, 1); paneForInfo.add(tfSpeed, 1, 1); paneForInfo.add(new Label("Image file prefix"), 0, 2); paneForInfo.add(tfPrefix, 1, 2); paneForInfo.add(new Label("Number of images"), 0, 3); paneForInfo.add(tfNumberOfImages, 1, 3); paneForInfo.add(new Label("Audio file URL"), 0, 4); paneForInfo.add(tfURL, 1, 4); // Create a border pane BorderPane pane = new BorderPane(); pane.setBottom(paneForInfo); pane.setCenter(paneForImage); pane.setTop(btStart); pane.setAlignment(btStart, Pos.TOP_RIGHT); // Create animation animation = new Timeline( new KeyFrame(Duration.millis(1000), e -> nextImage())); animation.setCycleCount(Timeline.INDEFINITE); // Create and register the handler btStart.setOnAction(e -> { if (tfURL.getText().length() > 0) { MediaPlayer mediaPlayer = new MediaPlayer( new Media(tfURL.getText())); mediaPlayer.play(); } if (tfSpeed.getText().length() > 0) animation.setRate(Integer.parseInt(tfSpeed.getText())); animation.play(); }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 550, 680); primaryStage.setTitle("Exercise_16_23"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example #26
Source File: MediaSimplPane.java From oim-fx with MIT License | 4 votes |
/** * 设置播放视频文件地址<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 #27
Source File: MediaPlayerScene.java From aurous-app with GNU General Public License v2.0 | 4 votes |
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); }
Example #28
Source File: UISession.java From aurous-app with GNU General Public License v2.0 | 4 votes |
public static Media getMedia() { return media; }
Example #29
Source File: UISession.java From aurous-app with GNU General Public License v2.0 | 2 votes |
public static void setMedia(final Media media) { UISession.media = media; }