I need to be able to run a .mp3 file using Java, I have tried this, but to no avail:
Process process = new ProcessBuilder("C:\\Users\\<removed>\\Desktop\\Music\\Cash Cash\\Overtime.mp3")
and then running
process.start();
But, it throws this error:
java.io.IOException: Cannot run program "C:\Users\<removed>\Desktop\Music\Cash Cash\Overtime.mp3": CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at com.newgarbo.music.Mooseec.main(Mooseec.java:50)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 2 more
I assume this is of course because a Process
is only for executables/jars, and if it is so, then can someone please show me a way to run these files? ^_^
You could use Desktop.open(File)
to launch the associated application to open the file. Something like,
File mp3 = new File("C:\\Users\\<removed>\\Desktop\\"
+ "Music\\Cash Cash\\Overtime.mp3");
Desktop.getDesktop().open(mp3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With