IO stream processing for Java music playback

Source: Internet
Author: User

This class can only be played all the time. Know that the music is over.

A little better than AUDIOCILP.

Import Java.io.*;import javax.sound.sampled.*;p ublic class Test {public static void main (string[] args) {Aeplaywave apw=n EW Aeplaywave ("./111.wav"); Apw.start ();}} Class Aeplaywave extends Thread {private string Filename;public Aeplaywave (String wavfile) {filename = wavfile;} public void Run () {file Soundfile = new File (filename); Audioinputstream Audioinputstream = null;try {audioinputstream = Audiosystem.getaudioinputstream (soundFile);} catch ( Exception E1) {e1.printstacktrace (); return;} Audioformat format = Audioinputstream.getformat (); Sourcedataline Auline = Null;dataline.info Info = new Dataline.info (sourcedataline.class, format); try {auline = (SourceDa Taline) Audiosystem.getline (info); auline.open (format);} catch (Exception e) {e.printstacktrace (); return;} Auline.start (); int nbytesread = 0;byte[] AbData = new Byte[512];try {while (nbytesread! =-1) {Nbytesread = Audioinputstre Am.read (abData, 0, abdata.length); if (nbytesread >= 0) auline.write (abData, 0, Nbytesread);}} catch (IOexception e) {e.printstacktrace (); return;} finally {Auline.drain (); Auline.close ();}}} 










IO stream processing for Java music playback

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.