-2

I want to add audio to my JavaFX project in Replit. Is there a way to use a public accessible URL link that references an .mp3 file in order to play audio?

For example, the following allows me to include an image only using a URL without having to reference a file:

Image image= new Image("https://cdn.discordapp.com/attachments/952426047645843537/954119846046629928/play3.png");

Is something similar possible for audio files?

  • 1
    what's the problem _exactly_? sounds like you need to learn some java language basics like resource lookup plus which parameters the class you want to use needs .. – kleopatra Mar 25 '22 at 10:42
  • Hello NewtonPearson, welcome to Stack Overflow! Before asking a question on Stack Overflow, please always try to do at least some minimal research by searching for existing questions in SO and, in a case like this, by looking at the API documentation of JavaFX: https://stackoverflow.com/search?q=javafx+audio+url and https://openjfx.io/javadoc/18/javafx.media/javafx/scene/media/AudioClip.html – Bernhard Stadler Mar 25 '22 at 17:32

1 Answers1

0

You can try this

Media sound = new Media("https://yourURL/file.mp3");
MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.play();
Tristate
  • 1,498
  • 2
  • 18
  • 38
  • This works, [AudioClip](https://openjfx.io/javadoc/17/javafx.media/javafx/scene/media/AudioClip.html#%3Cinit%3E(java.lang.String)) is another alternative. Both AudioClip and Media require the [javafx.media module](https://stackoverflow.com/a/64016989/1155209). – jewelsea Mar 25 '22 at 11:37
  • @jewelsea JavaFX on Replit does not come with a module-info.java file, I tried manually adding one and copying and pasting this: module org.project { requires javafx.controls; requires javafx.fxml; requires javafx.media; opens org.project to javafx.fxml; exports org.project; } How would I go about adding a module? The template has pre-built files that are a lot more confusing than what I'm used to on Eclipse. – NewtonPearson Mar 25 '22 at 20:33