Friday, May 29, 2009

SWING JApplet with multimedia

Play Audio in JApplet
When playing music, AudioClip object is needed, which play *.au and *.wav files.
There are three methods on AudioClip objects:
• play(): it plays the audio file once and stop.
• loop(): it plays the audio file repeatedly until the stop method is called.
• stop(): it stops a loop play of an audio clip.

To test the code, get any wav files, rename them to shutter.wav and tuner2.wav, then copy them to your DocumentBase directory (just uncomment //System.out.println("DocumentBase="+getDocumentBase()); to find out).

Show Code   Hide Code



Play Video in JApplet
When playing video a Manager class and a player object are needed.
There are there control methods on the player object:
player.start()
player.stop()
player.close()

Java Media Framework (JMF) API is needed for import javax.media.*;
You need to download JMF library for compiling the code.

To test the code, get any mpg file, rename it to phantom.mpg, then copy it to your DocumentBase directory (just uncomment //System.out.println("DocumentBase="+getDocumentBase()); to find out).

Show Code   Hide Code


download the supporting files and code from here.

No comments:

Post a Comment

Why I stopped publishing blog posts as information provider

Now the AI can generate content. Does that mean the web publishing industry reaches the end? ChatGPT said: ChatGPT Not at all. While AI can ...