Forum Stats

  • 3,854,261 Users
  • 2,264,344 Discussions
  • 7,905,624 Comments

Discussions

2 (Two) Same File Descriptors when Playing Movie using JavaFx

efe34034-c54f-4224-92af-40d726b324a3
edited Apr 12, 2017 4:14PM in JavaFX 2.0 and Later

I'm using JavaFx player for playing multimedia, however it seems that it gives me 2 same file descriptors when a specific

movie is playing, but it will remove one when it finishes playing.

My problem is that I should only have one file descriptor when playing a media, but it's giving me two 2.

May you help me about this.

Below is the snippet of my code

  Platform.runLater(new Runnable() {

   @SuppressWarnings({

    "rawtypes",

    "unchecked"

   })

   @Override

   public void run() {

    try {

     media = new Media(videoFile);

     if (media.getError() == null) {

      logger.info("Successfully created media object");

      media.setOnError(new Runnable() {

       public void run() {

        printErrorMessage(media.getError());

        return;

       }

      });

      try {

       if (player != null) player.dispose();

       player = new MediaPlayer(media);

       logger.info("Successfully created media player");

       player.setAutoPlay(true);

       player.setMute(true);

       if (player.getError() == null) {

        player.currentTimeProperty().addListener(new ChangeListener < Duration > () {

         private long prevTime;

         public void changed(ObservableValue < ? extends Duration > observable, Duration oldValue, Duration newValue) {

          long currTime = System.currentTimeMillis();

          if (Double.compare((currTime - prevTime), 5000) > 0) {

           System.out.println("delta: " + (currTime - prevTime) + ", old value: " + oldValue + ", new value: " + newValue + " Status : " + player.getStatus());

           prevTime = currTime;

          }

         }

        });

        mv = new MediaView(player);

        logger.info("Successfully created media view");

        mv.setSmooth(true);

        mv.setFitWidth(centerPane.getWidth());

        mv.setFitHeight(centerPane.getHeight());

        try {

         DoubleProperty mvw = mv.fitWidthProperty();

         mvw.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));

        } catch (Exception e) {

         logger.info("Width binding warning issue. " + e.toString());

        }

        mv.setPreserveRatio(true);

        mv.setOnError(new EventHandler() {

         public void handle(MediaErrorEvent t) {

          printErrorMessage(media.getError());

          return;

         }

         @Override

         public void handle(Event event) {

          printErrorMessage(media.getError());

          return;

         }

        });

        player.setOnEndOfMedia(new Runnable() {

         public void run() {

          player.stop();

          player.dispose();

          if (itr.hasNext()) {

           loadMedia(itr.next());

          } else {

           itr = list.iterator();

           loadMedia(itr.next());

          }

          return;

         }

        });

        player.setOnError(new Runnable() {

         public void run() {

          printErrorMessage(media.getError());

          return;

         }

        });

        player.setOnPlaying(new Runnable() {

         public void run() {

          logger.info("On Playing");

         }

        });

        player.setOnHalted(new Runnable() {

         public void run() {

          logger.info("On Halted");

         }

        });

        player.setOnPaused(new Runnable() {

         public void run() {

          logger.info("On Paused");

         }

        });

        player.setOnStopped(new Runnable() {

         public void run() {

          logger.info("On Stopped");

         }

        });

        //player.play();

        logger.info("MediaPlayer : Play, Memory : " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));

        logger.info("Is about to play : " + player.getMedia().getDuration().toMinutes());

        centerPane.getChildren().add(mv);

       } else {

        // Handle synchronous error creating MediaPlayer.

        logger.error("synchronous error");

        if (itr.hasNext()) {

         loadMedia(itr.next());

        } else {

         itr = list.iterator();

         loadMedia(itr.next());

        }

        return;

       }

      } catch (Exception mediaPlayerException) {

       logger.error("mediaPlayerException: " + mediaPlayerException.getMessage().toString());

       if (itr.hasNext()) {

        loadMedia(itr.next());

       } else {

        itr = list.iterator();

        loadMedia(itr.next());

       }

       return;

      }

     } else {

      // Handle synchronous error creating Media.

      logger.error("synchronous error");

      if (itr.hasNext()) {

       loadMedia(itr.next());

      } else {

       itr = list.iterator();

       loadMedia(itr.next());

      }

      return;

     }

    } catch (Exception mediaException) {

     logger.error("mediaException: " + mediaException.getMessage().toString());

     if (itr.hasNext()) {

      loadMedia(itr.next());

     } else {

      itr = list.iterator();

      loadMedia(itr.next());

     }

     return;

    }

   }

  });

Tagged:
This discussion has been closed.