import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class Sound extends javax.swing.JFrame {
/** Creates new form AudioLoopTest */
public Sound() {
initComponents();
}
public void playaudio() throws IOException{
System.out.println("Welcome in Audio Player");
InputStream in = new FileInputStream("music/one.mp3");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Sound().setVisible(true);
try {
new Sound().playaudio();
} catch (IOException ex) {
Logger.getLogger(Sound.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ex.toString());
}
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
(Both of the above codes are examples I copied, other users who used them said they worked fine)
Yet, it allows me to load an image using this code perfectly fine.
import java.awt.Image;
import javax.swing.ImageIcon;
public class Solid{
protected int width, height;
protected Image image;
public Solid(String icon) {
ImageIcon ii = new ImageIcon(this.getClass().getResource("images/" + icon));
image = ii.getImage();
width = ii.getIconWidth();
height = ii.getIconHeight();
}
}
Is there something I have to do in Eclipse before doing this? I haven't seen anything telling me to do so in any tutorials.
Also, I made sure the files were in the proper locations, I even tried doing exact locations using C://Users/...etc

New Topic/Question
Reply



MultiQuote






|