Last active
February 28, 2024 07:10
-
-
Save declank/ef7cab40910c21a06af2 to your computer and use it in GitHub Desktop.
Play an audio file in Scala (Command line/JavaFX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ensure you have jfxrt.jar added to the classpath | |
| import javafx.application.Application | |
| import javafx.scene.media.Media | |
| import javafx.scene.media.MediaPlayer | |
| import javafx.stage.Stage | |
| class MP3Player extends Application { | |
| def start(primaryStage: Stage) { | |
| val resource = getClass().getResource((getParameters().getRaw()).get(0)) | |
| val media = new Media(resource.toString()) | |
| new MediaPlayer(media).play() | |
| } | |
| } | |
| object MP3Player { | |
| def main(args: Array[String]) { | |
| Application.launch(classOf[MP3Player], args: _*) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment