I am trying to play a song from java and I have successfully played a different song from the same code (but to a different URL). I found out that most of the sites that you can upload files to (dropbox etc.) require you to be signed in with cookies and such. I know java doesn't have my gmail login and access to my dropbox account. I am looking for either a way to get the file locally (I did and it can tell me how big the file is but not play it(GRRRR)) or a website that keeps the files uploaded without any protection. Here is the code:
package playsound;
import java.net.URL;
import javax.sound.sampled.*;
import java.io.File;
public class LoopSound {
public static void main(String[] args) throws Exception {
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
File file = new File("c:/Users/liam/workspace/playsound/song.wav");
System.out.println("length : " + file.length());
URL url = new URL(
"https://www.dropbox.com/s/n9plhbvwy7drhvy/song.wav?dl=0");
//"http://www.intriguing.com/mp/_sounds/hg/fart.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.
getAudioInputStream( url );
clip.open(ais);
clip.loop(5);
javax.swing.JOptionPane.showMessageDialog(null, "Close to exit!");
}
}
The Fart thing was the one that did work for me. I will clarify if needed.
Exception in thread "main" javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input URL
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at playsound.LoopSound.main(LoopSound.java:20)