i have this code:
which should play a sound file when the application is loaded up but it doesntCode:try { InputStream in = new FileInputStream("1941krote.au"); AudioStream as = new AudioStream(in); AudioPlayer.player.start(as); }catch (IOException e) { }
if you want to see the full code its:
Can you find out why it does not play the audio file please.Code:import java.awt.*; import java.io.*; import java.awt.event.*; import javax.swing.*; import sun.audio.*; import java.util.*; import java.net.*; import java.applet.*; public class test2 extends JFrame implements KeyListener { int right = 225; int up = 225; ImageIcon snake; Container f2; String test; public test2() { super("FSnake"); f2 = getContentPane(); f2.setLayout(new FlowLayout()); String mediaName = "1941krote.mid"; snake = new ImageIcon("tn_ea03.jpg"); setVisible(true); setSize(500,500); addKeyListener(this); } public void keyReleased(KeyEvent event){ System.out.println( "Key pressed: %s" + event.getKeyText( event.getKeyCode() ) ); } public void keyTyped(KeyEvent event){ System.out.println( "Key pressed: %s" + event.getKeyText( event.getKeyCode() ) ); } public void paint(Graphics g){ super.paint(g); g.drawImage( snake.getImage(), up, right, null ); } public void repaint() { paint(getGraphics()) ; } public void keyPressed(KeyEvent event) { System.out.println( "Key pressed: %s" + event.getKeyText( event.getKeyCode() ) ); // output pressed key right = right - 50; repaint(); } public static void main(String[] args){ test2 application = new test2(); try { InputStream in = new FileInputStream("C:/Program Files/Xinox Software/JCreatorV3LE/MyProjects/Snake/1941krote.au"); AudioStream as = new AudioStream(in); AudioPlayer.player.start(as); }catch (IOException e) { } } }


Reply With Quote


Bookmarks