Playing a mp3 file

im making a game for school, were using html css and js but only coding in the index.java file. i want to play a music mp3 file as background music so i went into a seperate repl to test the code for the music. i looked up help online and asked my teacher to try to get it to work but we have gotten absolutely nothing to work and idk what im doing wrong. here is my code:

import ddf.minim.*;
Minim minim;
AudioPlayer music;

void setup(){
minim = new Minim(this);
music = minim.loadFile(“virtualinsanity.mp3”);
music.play();
}

ive also tried this:

import processing.sound.*;
SoundFile music;

void setup(){
music = new SoundFile(this, “virtualinsanity.mp3”);
music.play();
}

ive tried converting the file to wav and aiff and triple checked if im spelling the file name right but i keep on getting a null error.

Hi @AramAsdourian

Could you use <AUDIO> HTML tags instead? That might work.

I’ve not tried the above code yet but think that the issue would be related to import ddf.minim

If you could share a link to the Repl it would be useful for others in the community.

1 Like

here is he link to my code:
https://replit.com/@AramAsdourian/test#index.java

i have not tried anything with html yet because i would like to try to keep everything in index.java, unless if there is a way to have the audio tag in html react to a variable change in index.java which is what i was going to have happen inside index.java eventually.

Hi @AramAsdourian, there is a difference between JavaScript and Java. You can’t run Java inside an HTML, CSS, JS Repl. Instead, you should create a new Java Repl.

6 Likes