changeset 9266:222d8f8a82c6

8134353: [Mac] Ensemble Media samples sliders don't react to clicks Reviewed-by: kcr
author Morris Meyer <morris.meyer@oracle.com>
date Tue, 22 Sep 2015 13:51:20 -0400
parents d32c32056ba1
children 98bb3d975bb6
files apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/OverlayMediaPlayerApp.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/PlayerPane.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/PlayerPane.java apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/StreamingMediaPlayerApp.java
diffstat 4 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/OverlayMediaPlayerApp.java	Tue Sep 22 10:23:09 2015 -0400
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/OverlayMediaPlayerApp.java	Tue Sep 22 13:51:20 2015 -0400
@@ -77,7 +77,8 @@
         if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) {
             return;
         }
-        if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.STOPPED || status == MediaPlayer.Status.READY) {
+        if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.STOPPED ||
+            status == MediaPlayer.Status.READY) {
             mediaPlayer.play();
         }
     }
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/PlayerPane.java	Tue Sep 22 10:23:09 2015 -0400
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/overlaymediaplayer/PlayerPane.java	Tue Sep 22 13:51:20 2015 -0400
@@ -50,6 +50,7 @@
 import javafx.scene.control.ToolBar;
 import javafx.scene.input.MouseEvent;
 import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
 import javafx.scene.layout.Region;
 import javafx.scene.media.MediaPlayer;
 import javafx.scene.media.MediaView;
@@ -149,7 +150,8 @@
                 transition.play();
             });
 
-            mp.currentTimeProperty().addListener((ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) -> {
+            mp.currentTimeProperty().addListener((ObservableValue<? extends Duration> observable,
+                                                  Duration oldValue, Duration newValue) -> {
                 updateValues();
             });
             mp.setOnPlaying(() -> {
@@ -182,14 +184,19 @@
             timeSlider.setId("media-slider");
             timeSlider.setMinWidth(200);
             timeSlider.setMaxWidth(Double.MAX_VALUE);
-            timeSlider.valueProperty().addListener((Observable ov) -> {
+            timeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable,
+                                                    Number old, Number now) -> {
                 if (timeSlider.isValueChanging()) {
                     // multiply duration by percentage calculated by slider position
                     if (duration != null) {
                         mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
                     }
                     updateValues();
-                    
+                } else if (Math.abs(now.doubleValue() - old.doubleValue()) > 1.5) {
+                    // multiply duration by percentage calculated by slider position
+                    if (duration != null) {
+                        mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
+                    }
                 }
             });
             mediaTopBar.getChildren().add(timeSlider);
@@ -216,11 +223,15 @@
             volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
             volumeSlider.valueProperty().addListener((Observable ov) -> {
             });
-            volumeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
+            volumeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable,
+                                                      Number old, Number now) -> {
                 if (volumeSlider.isValueChanging()) {
                     mp.setVolume(volumeSlider.getValue() / 100.0);
+                } else {
+                    mp.setVolume(volumeSlider.getValue() / 100.0);
                 }
             });
+            HBox.setHgrow(volumeSlider, Priority.ALWAYS);
             mediaTopBar.getChildren().add(volumeSlider);
                         
             final EventHandler<ActionEvent> backAction = (ActionEvent e) -> {
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/PlayerPane.java	Tue Sep 22 10:23:09 2015 -0400
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/PlayerPane.java	Tue Sep 22 13:51:20 2015 -0400
@@ -131,7 +131,8 @@
         BorderPane.setAlignment(mediaTopBar, Pos.CENTER);
 
 
-        mp.currentTimeProperty().addListener((ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) -> {
+        mp.currentTimeProperty().addListener((ObservableValue<? extends Duration> observable,
+                                              Duration oldValue, Duration newValue) -> {
             updateValues();
         });
         mp.setOnPlaying(() -> {
@@ -163,14 +164,19 @@
         timeSlider.setId("media-slider");
         timeSlider.setMinWidth(240);
         timeSlider.setMaxWidth(Double.MAX_VALUE);
-        timeSlider.valueProperty().addListener((Observable ov) -> {
+        timeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable,
+                                                Number old, Number now) -> {
             if (timeSlider.isValueChanging()) {
                 // multiply duration by percentage calculated by slider position
                 if (duration != null) {
                     mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
                 }
                 updateValues();
-                
+            } else if (Math.abs(now.doubleValue() - old.doubleValue()) > 1.5) {
+                // multiply duration by percentage calculated by slider position
+                if (duration != null) {
+                    mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
+                }
             }
         });
         HBox.setHgrow(timeSlider, Priority.ALWAYS);
@@ -192,14 +198,20 @@
         volumeSlider = new Slider();
         volumeSlider.setId("media-slider");
         volumeSlider.setPrefWidth(120);
-        volumeSlider.setMaxWidth(Double.MAX_VALUE);
+        volumeSlider.setMinWidth(30);
+        volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
         volumeSlider.valueProperty().addListener((Observable ov) -> {
         });
-        volumeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
+        volumeSlider.valueProperty().addListener((ObservableValue<? extends Number> observable,
+                                                  Number old, Number now) -> {
+            
             if (volumeSlider.isValueChanging()) {
                 mp.setVolume(volumeSlider.getValue() / 100.0);
+            } else {
+                mp.setVolume(volumeSlider.getValue() / 100.0);
             }
         });
+        
         HBox.setHgrow(volumeSlider, Priority.ALWAYS);
         mediaTopBar.getChildren().add(volumeSlider);
 
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/StreamingMediaPlayerApp.java	Tue Sep 22 10:23:09 2015 -0400
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/media/streamingmediaplayer/StreamingMediaPlayerApp.java	Tue Sep 22 13:51:20 2015 -0400
@@ -54,7 +54,7 @@
 public class StreamingMediaPlayerApp extends Application {
 
     private String streamingMediaPlayerCss = StreamingMediaPlayerApp.class.getResource("StreamingMediaPlayer.css").toExternalForm();
-    private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/JavaRap/prog_index.m3u8";
+    private static final String MEDIA_URL = "http://download.oracle.com/otndocs/javafx/JavaRap_ProRes_H264_768kbit_Widescreen.mp4";
     private MediaPlayer mediaPlayer;
 
     public Parent createContent() {
@@ -74,7 +74,8 @@
         if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) {
             return;
         }
-        if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.STOPPED || status == MediaPlayer.Status.READY) {
+        if (status == MediaPlayer.Status.PAUSED || status == MediaPlayer.Status.STOPPED ||
+            status == MediaPlayer.Status.READY) {
             mediaPlayer.play();
         }
     }