14 Replies Latest reply: Jun 6, 2013 12:34 PM by James_D RSS

    Audio player problem !!

    1010912
      Hey amigoses ^^
      I'm a little bit stuck again with this time trying to make a mere mp3 player !!
      Probabilly the most simple one !!
      I have a list view that will contain the music titles but again, nothing comes that esay ^^
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package audioplayer;
      
      
      import java.io.File;
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ListView;
      import javafx.scene.control.Slider;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.stage.FileChooser;
      import javafx.stage.FileChooser.ExtensionFilter;
      import javafx.stage.Stage;
      
      /**
       *
       * @author Minedun6
       */
      public class AudioPlayer extends Application {
          ListView list = new ListView();
          Button btn_load = new Button("Load File");
          Button btn_play = new Button("play");
          Button btn_stop = new Button("Stop");
          Button btn_pause = new Button("Pause");
          ObservableList<String> array;
          FileChooser chooser = null;
          File file;
          Media media;
          MediaPlayer player;
          Slider longeur;
          @Override
          public void start(Stage primaryStage) {
              list.setLayoutX(210);
              list.setLayoutY(10);
              list.setPrefSize(160, 260);
              btn_load.setLayoutX(295);
              btn_load.setLayoutY(260);
              btn_stop.setLayoutX(50);
              btn_pause.setLayoutX(100);
              longeur.setPrefSize(150,10);
              longeur.setLayoutX(5);
              longeur.setLayoutY(50);
              
              
              
              
              
              
              
              
              btn_load.setOnMouseClicked(new EventHandler<MouseEvent>(){
      
                  @Override
                  public void handle(MouseEvent t) {
                     chooser = new FileChooser();
                     ExtensionFilter mp3 = new ExtensionFilter("MP3 Files(*.mp3)", "*.mp3");
                     ExtensionFilter aac = new ExtensionFilter("AAC Files(*.aac)", "*.aac");
                     chooser.getExtensionFilters().addAll(mp3,aac);
                      file = chooser.showOpenDialog(null);
                     String fi = file.getAbsoluteFile().toURI().toString();
                     String name = file.getName().toString();
                     list.getItems().add(name);
                      array = FXCollections.observableArrayList();
                      array.addAll(fi);
                      System.out.println(array);
                  }
              });
              
              btn_play.setOnMouseClicked(new EventHandler<MouseEvent>(){
      
                  @Override
                  public void handle(MouseEvent t) {
                      media = new Media(array.get(list.getSelectionModel().getSelectedIndex()).toString()); 
                      player = new MediaPlayer(media);
                      player.play();
                  }
                  
              });
              
              btn_stop.setOnMouseClicked(new EventHandler<MouseEvent>(){
      
                  @Override
                  public void handle(MouseEvent t) {
                      player.stop();
                  }
                  
              });
              
              btn_pause.setOnMouseClicked(new EventHandler<MouseEvent>(){
      
                  @Override
                  public void handle(MouseEvent t) {
                      player.pause();
                  }
                  
              });
              
              
              Group root = new Group();
              root.getChildren().addAll(list,btn_load,btn_play,btn_stop,btn_pause,longeur);
              
              Scene scene = new Scene(root, 400, 300);
              
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      
          /**
           * The main() method is ignored in correctly deployed JavaFX application.
           * main() serves only as fallback in case the application can not be
           * launched through deployment artifacts, e.g., in IDEs with limited FX
           * support. NetBeans ignores main().
           *
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
      }
      I really tried to do something very simple but seems no !!
      And by the way, the pause button, when i press on it, it should only pauses the play but seems it's making the player stop not pause ^^
        • 1. Re: Audio player problem !!
          James_D
          So what happens when you run it?

          I'm kind of guessing you get a NullPointerException...?

          The trick to debugging those is to identify the line in your code where it occurred. The object on which you called the method in that line is the object that is null.
          • 2. Re: Audio player problem !!
            1010912
            no the proble is not there amigo ^^
            the load button should enable you to load the mp3 files !!
            the problem is that when i hit the play button, it will only play the last loaded mp3 file !!
            I've made an ObservableArrayList trying to solve this, so what it does !!
            btn_load.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent t) {
                            chooser = new FileChooser();
                            ExtensionFilter mp3 = new ExtensionFilter("MP3 Files(*.mp3)", "*.mp3");
                            ExtensionFilter aac = new ExtensionFilter("AAC Files(*.aac)", "*.aac");
                            chooser.getExtensionFilters().addAll(mp3, aac);
                            file = chooser.showOpenDialog(null);
                            String fi = file.getAbsoluteFile().toURI().toString();
                            String name = file.getName().toString();
                            list.getItems().add(name);
                            array = FXCollections.observableArrayList();
                            array.addAll(fi);
                            System.out.println(array);
                        }
                    });
            here, what you'll find is the load method, yu see that normally each time i load an item, the fi variable that contains the url of the file will be added to the observablearraylist !!
            so now when i press an item in the listview, i should get an position of the selecteditem !!
            instead the observablearraylist gets only the last item i add, that's what's bothering me !!

            for further explanation, here's an exemple !!
            so i have 2 mp3 files that i'll load, "a.mp3" and "b.mp3" !!
            when i load the first one, the observablearraylist will only contain the url of the only loaded mp3 file which is "a.mp3" but when i load the second file, the observablearraylist will only have now the url of the second loaded mp3 file which is "b.mp3"

            I really hope i made myself clear enough ^^
            • 3. Re: Audio player problem !!
              James_D
              OK - you must have some code that's not included in your first post. The variable longeur is not initialized before you call setPrefSize(...) on it. But that's fine...

              The reason you only see the last file in your ObsersvableList ("array") is that when the user presses the load button you do
              array=FXCollections.observableArrayList();
              which creates a new, empty list. So you're replacing the entire list every time, and then adding the one element to it.

              But you don't really need this observable list at all. The ListView already has a list of everything it displays. You can always get this list with list.getItems().
              If you want the selected item, you can do list.getSelectionModel().getSelectedItem(). So your play button should do
              media = new Media((String) list.getSelectionModel().getSelectedItem());
              If you declare the ListView correctly:
              ListView<String> list = new ListView<String>();
              then you don't need the downcast when you get the selected item:
              media = new Media(list.getSelectionModel().getSelectedItem());
              Incidentally, you should use setOnAction(...) for the Buttons, not setOnMouseClicked(...). The reason is that if the user navigates around your application using the keyboard (for example using the tab key), they'd expect the space bar to press a button when it had focus. The onMouseClicked handler won't be called in this case (the mouse wasn't clicked...), but a handler for an ActionEvent will:
                      btn_play.setOnAction(new EventHandler<ActionEvent>(){
               
                          @Override
                          public void handle(ActionEvent t) {
                              media = new Media(list.getSelectionModel().getSelectedItem()); 
                              player = new MediaPlayer(media);
                              player.play();
                          }
                          
                      });
              • 4. Re: Audio player problem !!
                1010912
                I might correct for something, what i'm storing in the listview is juste the name of the mp3 file not the directory where is the mp3 file ^^
                i used the observablearraylist juste to store the string directories ^^
                And since the mp3 files are chosen in a certain order, for each chosen item in the listview i get its directory from the observablearraylist ^^
                But the problem is that i put the
                 array = FXCollections.ObservableArrayList(); 
                inside the load_button ^^ no wonder the arraylist was filled with only the mp3 file i load !!
                Again, thx James D for the awesome tips ^^
                • 5. Re: Audio player problem !!
                  James_D
                  Ah - I didn't notice that the Strings you were putting in your ObservableList were different to the Strings you were putting in your ListView. That explains why you were using a separate list. To make that work, just initialize the list once, in your start method, with
                  array = FXCollections.observableList();
                  and then just add the required elements to it each time with the load button's onAction handler.

                  In general, it can be a bit of a pain to maintain two lists of things that you have to keep in sync. (If you want to add more functionality to this, like letting the user remove songs, or sort them, etc, then you have to be really careful to make sure the two lists stay in sync correctly.) You can end up introducing a lot of bugs that are hard to track down.

                  The other approach would be to store the Files in the list view, instead of the file names. The reason for this is that you can get all the information you want from the File objects in the ListView.

                  For this approach, you'd do
                  ListView<File> list = new ListView<File>();
                  in the initializer.

                  Then in the load button's handler, do
                  file = chooser.showOpenDialog();
                  if (file != null) { // in case the user canceled...
                    list.getItems().add(file);
                  }
                  And for the play button:
                  media = new Media(list.getSelectionModel().getSelectedItem().toURI().toString());
                  So here you store the Files (really the location of the file on the file system, not the contents of the file) in the ListView, and get the required information from them when you need it.

                  The only problem now is that the display in the ListView is ugly. To fix this, instead of changing what's stored in the ListView, change the way the ListView displays its contents. This is a little more code, but is definitely worth it in order to avoid keeping multiple data structure in sync.

                  You need this:
                      class FilenameListCell extends ListCell<File> {
                        @Override
                        public void updateItem(File file, boolean empty) {
                          super.updateItem(file, empty);
                          if (empty) {
                            setText(null);
                          } else {
                            String filename = file.getName();
                            int extensionIndex = filename.lastIndexOf(".");
                            if (extensionIndex >= 1) {
                              filename = filename.substring(0, extensionIndex);
                            }
                            setText(filename);
                          }
                        }
                      }
                  
                      list.setCellFactory(new Callback<ListView<File>, ListCell<File>>() {
                        @Override
                        public ListCell<File> call(ListView<File> listView) {
                          return new FilenameListCell();
                        }
                      });
                  It can go in the start() method in its entirety, or the class definition can go outside the start() method, with the list.setCellFactory(...) in the start() method. Note that I stripped the file extension off the filename, which I think looks a little better.
                  You could do more with this if you wanted, like setting a different graphic for different file types.
                  • 6. Re: Audio player problem !!
                    1010912
                    I have better one that calling the cellFactory and so on ^^
                    When i get the URL of my file, i'll be doing some modification ^^
                    if(file !=null){
                                        String fi = file.getAbsoluteFile().toURI().toString();
                                        String name = file.getName().toString().substring(0,file.getName().toString().lastIndexOf("."));
                                        list.getItems().add(name);
                                    }
                    another way to personalize the display inside the listview without too much code^^
                    Again, thx James D !
                    • 7. Re: Audio player problem !!
                      James_D
                      1007909 wrote:
                      I have better one that calling the cellFactory and so on ^^
                      When i get the URL of my file, i'll be doing some modification ^^
                      if(file !=null){
                      String fi = file.getAbsoluteFile().toURI().toString();
                      String name = file.getName().toString().substring(0,file.getName().toString().lastIndexOf("."));
                      list.getItems().add(name);
                      }
                      That's fine, as long as the filename has an extension (if not, you'll get a nice StringIndexOutOfBoundsException...). Your file filters do guarantee an extension, so you should be safe.
                      another way to personalize the display inside the listview without too much code^^
                      Not really. They did a really good job of making the cells in ListViews (and TableViews, TreeViews, etc) very flexible and also very efficient: but that comes at the price of some slightly verbose code.
                      Java 8 will make it a bit cleaner, but not a lot.

                      Aim for clean, easy to read, code, rather than short code, though. If you want the least possible amount of code, Java simply isn't the correct solution.

                      I suppose one other option would be to define a Song class:
                      import java.net.URI ;
                      public class Song {
                       private final URI uri ;
                       private final String name ;
                       public Song(URI uri, String name) {
                         this.uri = uri ;
                         this.name = name ;
                       }
                       public URI getUri() {
                        return url ;
                       }
                       public String getName() {
                         return name ;
                       }
                       @Override
                       public String toString() {
                        return getName();
                       }
                      }
                      Then make your ListView a
                      ListView<Song> list = new ListView<Song>();
                      Your load button handler becomes
                      if(file !=null){
                        URI uri = file.getAbsoluteFile().toURI();
                        String name = file.getName().toString().substring(0,file.getName().toString().lastIndexOf("."));
                        list.getItems().add(new Song(uri, name));
                      }
                      and your play button does
                      ...
                      Media media = new Media(list.getSelectionModel().getSelectedItem().getUri().toString());
                      ...
                      So now you have one additional (small) source file, but actually shorter and cleaner code in your Application (again, this avoids the use of a second list). You have to figure out which trade-off works best for you.

                      Again, thx James D !
                      • 8. Re: Audio player problem !!
                        1010912
                        Ah now that i remember, let me ask yu this James D !!
                        For the topic of "rendering" images inside the combobox, yu've used an enum structure and yu've written something like this !!
                        enum Browser{
                        CHROME(chrome, "link");
                        SAFARI(safari,"link");
                        FIREFOX(firefox,"link");
                        ........
                        but the thing here is that since all the data comes from the database, i do no longer know how much of this are going to be ^^
                        So could I again count on yur help ^^ ?
                        • 9. Re: Audio player problem !!
                          1010912
                          @James D
                          I was wondering if there is a way to disable the buttons (all of them) if the list does not contain elements and become enabled again if the list is updated of something like that !!
                          • 10. Re: Audio player problem !!
                            James_D
                            1007909 wrote:
                            Ah now that i remember, let me ask yu this James D !!
                            For the topic of "rendering" images inside the combobox, yu've used an enum structure and yu've written something like this !!
                            enum Browser{
                            CHROME(chrome, "link");
                            SAFARI(safari,"link");
                            FIREFOX(firefox,"link");
                            ........
                            but the thing here is that since all the data comes from the database, i do no longer know how much of this are going to be ^^
                            So could I again count on yur help ^^ ?
                            Same idea, but don't use an enum, use a regular class.

                            Edited by: James_D on Jun 5, 2013 5:06 PM
                            • 11. Re: Audio player problem !!
                              James_D
                              1007909 wrote:
                              @James D
                              I was wondering if there is a way to disable the buttons (all of them) if the list does not contain elements and become enabled again if the list is updated of something like that !!
                              playButton.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                              Edited by: James_D on Jun 5, 2013 5:06 PM
                              • 12. Re: Audio player problem !!
                                1010912
                                Thx again !!
                                For the images/text, i'll be trying myself to do something and i hope this time i'll do it without yur help !!

                                As for the Mp3 Player, here is the code, would be nice of to see if there is something that can be added, perfectionized !!
                                /*
                                 * To change this template, choose Tools | Templates
                                 * and open the template in the editor.
                                 */
                                package audioplayer;
                                
                                import java.io.File;
                                import javafx.application.Application;
                                import javafx.beans.InvalidationListener;
                                import javafx.beans.Observable;
                                import javafx.beans.binding.Bindings;
                                import javafx.beans.value.ChangeListener;
                                import javafx.beans.value.ObservableValue;
                                import javafx.collections.FXCollections;
                                import javafx.collections.ObservableList;
                                import javafx.event.ActionEvent;
                                import javafx.event.EventHandler;
                                import javafx.scene.Group;
                                import javafx.scene.Scene;
                                import javafx.scene.control.Button;
                                import javafx.scene.control.Label;
                                import javafx.scene.control.ListView;
                                import javafx.scene.control.Slider;
                                import javafx.scene.input.KeyCode;
                                import javafx.scene.input.KeyEvent;
                                import javafx.scene.input.MouseEvent;
                                import javafx.scene.layout.AnchorPane;
                                import javafx.scene.media.Media;
                                import javafx.scene.media.MediaPlayer;
                                import javafx.scene.paint.Color;
                                import javafx.scene.paint.LinearGradient;
                                import javafx.stage.FileChooser;
                                import javafx.stage.FileChooser.ExtensionFilter;
                                import javafx.stage.Stage;
                                import javafx.util.Duration;
                                
                                /**
                                 *
                                 * @author Minedun6
                                 */
                                public class AudioPlayer extends Application {
                                
                                //Creating the GUI Form
                                    Button btn_play = new Button("Play");
                                    Button btn_pause = new Button("Pause");
                                    Button btn_stop = new Button("Stop");
                                    Button btn_previous = new Button("Prev");
                                    Button btn_next = new Button("Next");
                                    Button btn_load = new Button("Load");
                                    ListView list = new ListView();
                                    ObservableList array = FXCollections.observableArrayList();
                                    FileChooser choose;
                                    File file;
                                    Media media;
                                    MediaPlayer player;
                                    Slider status = new Slider();
                                    Slider volume = new Slider();
                                //End of GUI
                                
                                    @Override
                                    public void start(Stage stage) throws Exception {
                                        //Styling btn_previous
                                        btn_previous.setPrefSize(80, 30);
                                        btn_previous.setLayoutX(10);
                                        btn_previous.setLayoutY(330);
                                        //end of btn_previous
                                
                                        //Styling btn_pause
                                        btn_pause.setPrefSize(80, 30);
                                        btn_pause.setLayoutX(100);
                                        btn_pause.setLayoutY(330);
                                        //end of btn_pause
                                
                                        //Styling btn_play
                                        btn_play.setPrefSize(80, 30);
                                        btn_play.setLayoutX(190);
                                        btn_play.setLayoutY(330);
                                        //end of btn_play
                                
                                        //Styling btn_stop
                                        btn_stop.setPrefSize(80, 30);
                                        btn_stop.setLayoutX(280);
                                        btn_stop.setLayoutY(330);
                                        //end of btn_stop
                                
                                        //Styling btn_next
                                        btn_next.setPrefSize(80, 30);
                                        btn_next.setLayoutX(370);
                                        btn_next.setLayoutY(330);
                                        //end of btn_next
                                
                                        //Styling list
                                        list.setPrefSize(280, 300);
                                        list.setLayoutX(500);
                                        list.setLayoutY(10);
                                        //end of list
                                
                                        //Styling btn_load
                                        btn_load.setPrefSize(80, 30);
                                        btn_load.setLayoutX(600);
                                        btn_load.setLayoutY(330);
                                        //end of btn_load
                                
                                
                                        //Styling status slider
                                        status.setPrefSize(450, 10);
                                        status.setLayoutX(10);
                                        status.setLayoutY(290);
                                        //end of status slider
                                
                                        //Styling volume slider
                                        volume.setPrefSize(100, 10);
                                        volume.setLayoutX(350);
                                        volume.setLayoutY(310);
                                        volume.setValue(100.0);
                                        volume.setMin(0.0);
                                        volume.setMax(100.0);
                                        //end of volume slider
                                        
                                        btn_play.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                                        btn_next.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                                        btn_previous.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                                        btn_pause.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                                        btn_stop.disableProperty().bind(Bindings.isEmpty(list.getSelectionModel().getSelectedItems()));
                                
                                        list.setOnKeyReleased(new EventHandler< KeyEvent>(){
                                
                                            @Override
                                            public void handle(KeyEvent t) {
                                                if(t.getCode() == KeyCode.DELETE){
                                                    list.getItems().remove(list.getSelectionModel().getSelectedIndex());
                                                    array.remove(list.getSelectionModel().getSelectedIndex());
                                                }
                                            }
                                        
                                        });
                                        
                                        
                                        btn_load.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                            //Evenement associé au clic du bouton Load
                                            @Override
                                            public void handle(MouseEvent t) {
                                                //Ajout des Filtres de choix !!
                                                ExtensionFilter mp3 = new ExtensionFilter("MP3 Files(*.mp3)", "*.mp3");
                                                ExtensionFilter aac = new ExtensionFilter("AAC Files(*.aac)", "*.aac");
                                                choose = new FileChooser();
                                                choose.getExtensionFilters().addAll(mp3, aac);
                                                file = choose.showOpenDialog(null);
                                                if (file != null) {
                                                    //Ajout à la liste pour stocker les titres chansons !!
                                                    String fi = file.getAbsoluteFile().toURI().toString();
                                                    String name = file.getName().toString().substring(0, file.getName().toString().lastIndexOf("."));
                                                    list.getItems().add(name);
                                                    array.add(fi);
                                                }
                                            }
                                        });
                                
                                        btn_play.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                            //Evenement associé au click du button play
                                            @Override
                                            public void handle(MouseEvent t) {
                                                if (!(list.getItems().isEmpty())) {
                                                    //player.stop();
                                                    media = new Media(array.get(list.getSelectionModel().getSelectedIndex()).toString());
                                                    player = new MediaPlayer(media);
                                                    player.play();
                                                    player.setOnReady(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            status.setMin(0.0);
                                                            status.setValue(0.0);
                                                            status.setMax(player.getTotalDuration().toSeconds());
                                                            volume.setValue(100.0);
                                                            player.setVolume(100.0 / 100);
                                                            player.currentTimeProperty().addListener(new ChangeListener<Duration>() {
                                                                @Override
                                                                public void changed(ObservableValue<? extends Duration> ov, Duration t, Duration t1) {
                                                                    status.setValue(t1.toSeconds());
                                                                }
                                                            });
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                
                                        status.valueProperty().addListener(new InvalidationListener() {
                                            @Override
                                            public void invalidated(Observable o) {
                                                if (status.isValueChanging()) {
                                                    player.seek(Duration.seconds(status.getValue()));
                                                }
                                            }
                                        });
                                
                                        volume.valueProperty().addListener(new InvalidationListener() {
                                            @Override
                                            public void invalidated(Observable o) {
                                                if (volume.isValueChanging()) {
                                                    //le volume doit être divisé par 100 pour ressentir la dégradation du volume 
                                                    //sinon ça passe trop vite
                                                    player.setVolume(volume.getValue() / 100);
                                                }
                                            }
                                        });
                                
                                        btn_next.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                            @Override
                                            public void handle(MouseEvent t) {
                                                if ((list.getItems().size() != 0) || (list.getItems().get(list.getItems().size() + 1) != null)) {
                                                    player.stop();
                                                    list.getSelectionModel().selectNext();
                                                    media = new Media(array.get(list.getSelectionModel().getSelectedIndex()).toString());
                                                    player = new MediaPlayer(media);
                                                    player.play();
                                                    player.currentTimeProperty().addListener(new ChangeListener<Duration>() {
                                                                @Override
                                                                public void changed(ObservableValue<? extends Duration> ov, Duration t, Duration t1) {
                                                                    status.setValue(t1.toSeconds());
                                                                }
                                                            });
                                                }
                                            }
                                        });
                                
                                        btn_previous.setOnMouseClicked(new EventHandler<MouseEvent>() {
                                            @Override
                                            public void handle(MouseEvent t) {
                                                if ((list.getItems().size() != 0) || (list.getItems().get(-1) != null)) {
                                                    player.stop();
                                                    list.getSelectionModel().selectPrevious();
                                                    media = new Media(array.get(list.getSelectionModel().getSelectedIndex()).toString());
                                                    player = new MediaPlayer(media);
                                                    player.play();
                                                    player.currentTimeProperty().addListener(new ChangeListener<Duration>() {
                                                                @Override
                                                                public void changed(ObservableValue<? extends Duration> ov, Duration t, Duration t1) {
                                                                    status.setValue(t1.toSeconds());
                                                                }
                                                            });
                                                }
                                            }
                                        });
                                        
                                
                                        Group root = new Group();
                                        root.getChildren().addAll(btn_play, btn_previous,
                                                btn_pause, btn_stop, btn_next, btn_load, list,
                                                status, volume);
                                        Scene scene = new Scene(root, 800, 450);
                                        stage.setScene(scene);
                                        scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
                                        stage.setTitle("Audio Player");
                                        stage.show();
                                    }
                                    
                                    public void disableAll(){
                                        if(list.getItems().isEmpty()){
                                        btn_play.setDisable(true);
                                        btn_pause.setDisable(true);
                                        btn_next.setDisable(true);
                                        btn_previous.setDisable(true);
                                        btn_stop.setDisable(true);
                                        }
                                    }
                                
                                    public static void main(String[] args) {
                                        launch(args);
                                    }
                                }
                                • 13. Re: Audio player problem !!
                                  1010912
                                  James D,
                                  I really couldn't solve the problem of neither getting the data and putting them in the combobox !!
                                  try {
                                              c = connection.ConnecrDb();
                                              String sql ="select libelle_constr,img_constructeur from constructeurs;";
                                              pst = c.prepareStatement(sql);
                                              rs = pst.executeQuery();
                                              while(rs.next()){
                                                  byte[] buff = rs.getBytes("img_constructeur");
                                                  InputStream fis = new ByteArrayInputStream(buff);
                                                  img = new Image(fis);
                                                  box.getItems().addAll(img);
                                              }
                                          } catch (Exception e) {
                                          }
                                          box.getItems().addAll();
                                  What this does is adding the images and displaying them only when the contextmenu of the combobox is shown
                                  I would love that yu show me an exemple with this database exemple plz and plz plz plz every step yu'll be doing, write comments explaining procedures ^^
                                  • 14. Re: Audio player problem !!
                                    James_D
                                    1007909 wrote:
                                    James D,
                                    I really couldn't solve the problem of neither getting the data and putting them in the combobox !!
                                    What goes wrong?
                                    What this does is adding the images and displaying them only when the contextmenu of the combobox is shown
                                    I'm not clear if you're saying that this is what you want (why?) or that this is what's happening, and you don't want it.
                                    I would love that yu show me an exemple with this database exemple plz and plz plz plz every step yu'll be doing, write comments explaining procedures ^^
                                    That's quite a lot to ask.... especially as I think I've already answered all of that. If I have time I'll put something together...