JavaFX | Building a Media Player
This JavaFX library is used to make feature-rich internet apps (they offer similar experience and features as that of desktop apps). Like other Java libraries, the products built upon this library are platform independent, they can run on devices such as mobile phones, TVs, computers etc.
Other JVM based technologies like Groovy, JRuby etc can be used alongside JavaFX, however, the need seldom arises as JavaFX is offering most of the features itself. It is highly compatible with Java Swing, and its content can be embedded seamlessly in JavaFX apps.
Building a Media Player in JavaFX
For the media player application we would have three different classes the first one is our Main class which starts this application, then we have Player class to run our videos and audios and MediaBar class to control our media.
On running the above program on an offline IDE, the Media Player would look something like:
We have three classes over here-
1. Main class to launch our program
2. Player class to play our Media player
3. MediaBar class to add control to our control panel of media bar.
In our Main.java class which extends over the application class we have two methods one main method to launch the program and start method where we can set the stage and media control border. Then we have added the slider at the bottom for controlling the time of video and to control volume. In order to add functionality like to jump to a particular section of video we have used the-
And for changing the media
has been used in the above program. For styling purpose we have come up with the CSS which is depicted in
Among the best features of JavaFX is that one can control formatting with Cascading Style Sheets (CSS). We have used the .getStatus() function to check the status of player that whether it is halted, playing, stopped or paused and to take action accordingly.
Note:While importing select always the JavaFX files.
Please Login to comment...