A brief analysis of Java sound technology

Source: Internet
Author: User

One of the charms of Java is the support of multimedia, Appley makes the original dreary Web page become rich, and provides many powerful methods to support multimedia in Java.applet. Now we're going to analyze the capabilities of the sound technology in Java.

Play a sound in an applet

Playing sounds is an important part of Java's support for multimedia. Today's popular voice format has Wav,mid,au as an extension of the sound file. And Java is mainly supported by the AU-named voice. A class AudioClip is specifically provided in the applet to support sound.

Because the applet's multimedia function book all has the very clear introduction also very simple. Let's end this part of the description with an example.

import java.applet.*;
public class sounda extends Applet
{
public static void main (String[] args)
{
AudioClip ac = getAudioClip(getCodeBase(), "sloop.au");
ac.play();
// ac.loop();
// ac.stop();
}
}

The above example is simply a note that AudioClip is a playback class in Java. Two useful methods are provided in Java GetCodeBase (), getdocumentbase () They return the applet itself and the URL address that contains the applet's home page. The above sloop.au is the sound file on my machine. Here we use the AudioClip play method directly for playing the sound. You can test using the applet's image function to add buttons.

Sound playback in two Java applications

Because the AudioClip class is not supported in the application. So playing sound files has become a big problem. To make your own Java player or application media, can we not support the sound? No, Sun has provided a new Java package for voice support in the application. The Sun.audio provides most of the required sound processing classes below this package. Note: There are a lot of interesting technical support under sun bag, such as java2d,tools, we can try to use it.

Now let's do our own sound playback test.

import sun.audio.*;
import java.io.*;
public class Sound
{
public static voie main(String args[])
{
try {
FileInputStream fileau=new
FileInputStream("sloop.au");
AudioStream as=new AudioStream(fileau);
AudioPlayer.player.start(as);
}
catch (Exception e) {}
}
}

Note: Neither of the above offers the corresponding Stop method, this article refers to the attempt in the method, not a comprehensive article, but the above examples are available.

Application of sound package in three javax

As I was doing the above test, I found that the Javax directory also provides a strong support for Java sounds in the sound package, and downloads to a large number of sample programs on the Jjse of the Sun website. Friends who are interested in the direction of sound processing can download and try

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.