Introduction to some basic operation methods of multimedia files commonly used in Java
Play slides and animations
An example is given to illustrate the method of playing slides and animation.
[example] the applet first reads the slides into the array and stores them. Click the mouse to change the slides and display them one by one.
[example] the applet describes the method of playing animation. It requires that the played pictures and the applet be placed in the same directory. The program causes the effect of displaying animation by quickly displaying a group of pictures. The applet uses threads to control the display of animated pictures one by one.
Play sound
There are many audio formats in the old base of Java language: Au, AIFF, WAV, MIDI, RFM, etc. Applet to play audio files, you can use the class AudioClip, which is in Java applet. Defined in AudioClip class library. The applet first creates an AudioClip object and initializes it with the getaudioclip () method. The code form is as follows:
If you want to obtain audio files from the Internet, you can use the method getaudioclip (URL, string name) to obtain playable audio objects according to the URL address and audio file name.
There are three methods to control the playback of sound: play() to play the sound, loop() to cycle and stop().
[example] a small application that can play sound.
[example] if the sound file is large or the network speed is slow, it will affect the initialization of the applet. This can be solved by multithreading technology. The creation of audio objects is completed in a lower level thread, that is, the sound file is loaded in the background and played in the foreground.