0

im trying to execute this code :

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       try {
          JFXPanel j = new JFXPanel ();
          String uri = new File ("Alex Clare - Too Close.mp3").toURI().toString();
          MediaPlayer m = new MediaPlayer (new Media (uri)).play(); 
       }
       catch (Exception e)
       {
           
       }

my netbeans 15.4 didnt recognize those classes even i import them in the top of the program.what is the solution please ?

Moad
  • 1
  • Maybe a duplicate of [JavaFX MediaPlayer import](https://stackoverflow.com/questions/69976938/javafx-mediaplayer-import/69978264#69978264) – jewelsea Nov 18 '22 at 10:02
  • Your media player and player and media might get garbage collected if you don’t store references to them. – jewelsea Nov 18 '22 at 10:11
  • You aren’t using the JFXPanel. Perhaps [startup](https://openjfx.io/javadoc/19/javafx.graphics/javafx/application/Platform.html#startup(java.lang.Runnable)) the platform (once only) instead, if that is needed to play the mp3. If you do use the JFXPanel you need the javafx-swing dependency and to require the javafx.swing module, similar to javafx.media usage noted in the potential duplicate. – jewelsea Nov 18 '22 at 10:12
  • 1
    Unrelated, but if you can write your app using only JavaFX rather than mixing Swing, that is preferred. – jewelsea Nov 18 '22 at 10:14
  • [mcve] please - including the module info – kleopatra Nov 18 '22 at 12:33

0 Answers0