Java Audio - How to play song during game (Application, not Applet) -
Java Audio - How to play song during game (Application, not Applet) -
last edit - 2 simple answers needed.
1) able code working url (it's code 1 of responses below). song in wav file. when seek file url = new file("---");, doesn't work.
instead, in stack trace (thanks tip!), says
"failed allocate clip data: requested buffer large"
the song i'm trying play techno, 3 minutes long.
how work around clip info size issue?
look @ classes of java sound api sampled sound. particularly clip interface , audiosystem class.
java sound uses spi add together back upwards formats defaults built in j2se. can add together jmf based mp3plugin.jar provide back upwards mp3s javasound. playing wavs in loop, see little example..
import java.net.url; import javax.sound.sampled.*; public class loopsound { public static void main(string[] args) throws exception { url url = new url( "http://pscode.org/media/leftright.wav"); clip clip = audiosystem.getclip(); audioinputstream ais = audiosystem. getaudioinputstream( url ); clip.open(ais); clip.loop(5); javax.swing.joptionpane.showmessagedialog(null, "close exit!"); } }
java audio javasound
Comments
Post a Comment