Package one.jpro.platform.media.player


package one.jpro.platform.media.player

Media playback via MediaPlayer

The basic steps required to play media are:

  1. Create a MediaSource object for the desired media source.
  2. Create a MediaPlayer object from the MediaSource object via MediaPlayer.create(javafx.stage.Stage, MediaSource).
  3. Create a MediaView object via MediaView.create(MediaPlayer).
  4. Add the MediaView to the scene graph.
  5. Invoke MediaPlayer.play().
These steps are illustrated by the sample code in the MediaView class documentation. Some things which should be noted are:
  • One MediaSource object may be shared among multiple MediaPlayers.
  • Currently, one MediaPlayer may be shared among multiple MediaViews only in desktop/mobile application. In web application, each MediaView must have its own MediaPlayer object.
  • Media may be played directly by a MediaPlayer without creating a MediaView although a view is required for display.
  • Instead of MediaPlayer.play(), MediaPlayer.setAutoPlay(true) may be used to request that playing start as soon as possible. In web applications, the MediaPlayer may not start playing automatically when the web page is shown for the first time due to autoplay blocking policy of the browsers.
  • MediaPlayer has several operational states defined by MediaPlayer.Status.
Author:
Besmir Beqiri