Skip to content

Instantly share code, notes, and snippets.

@declank
Last active February 28, 2024 07:10
Show Gist options
  • Select an option

  • Save declank/ef7cab40910c21a06af2 to your computer and use it in GitHub Desktop.

Select an option

Save declank/ef7cab40910c21a06af2 to your computer and use it in GitHub Desktop.
Play an audio file in Scala (Command line/JavaFX)
// 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