public class MediaTools
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_AUDIO_PATH
The list of directories scanned for audio clips, separated by colons.
|
static java.lang.String |
DEFAULT_IMAGE_PATH
The list of directories scanned for images, separated by colons.
|
Modifier and Type | Method and Description |
---|---|
static void |
beep()
This method sounds the audible alert on the console, which is typically a beep
sound.
|
static java.applet.AudioClip |
createAudioClip(java.io.InputStream in)
Generates an audio clip from an input stream containing the data bytes for the
audio clip.
|
static java.applet.AudioClip |
createAudioClip(java.lang.String[] hexData)
Generates an audio clip from a string array that provides the pixel values.
|
static java.awt.Image |
createImage(java.io.InputStream in)
Generates an image from an input stream containing the data bytes for the
image formatted in image/gif format.
|
static java.awt.Image |
createImage(int[] pixels,
int width,
int height)
Generates an image from an array of pixel values.
|
static java.awt.Image |
createImage(java.lang.String[] hexData)
Generates an image from a string array that provides the pixel values.
|
static void |
defineAudioClip(java.lang.String name,
java.applet.AudioClip clip)
Inserts the given clip into the audio clip table under the specified name.
|
static void |
defineImage(java.lang.String name,
java.awt.Image image)
Inserts the given image into the image table under the specified name.
|
static void |
flushAudioClip(java.lang.String name)
Removes the audio clip with the given name from the cache, allowing it
to be freed by the garbage collector.
|
static void |
flushImage(java.lang.String name)
Removes the image with the given name from the cache, allowing it
to be freed by the garbage collector.
|
static java.io.InputStream |
getHexInputStream(java.lang.String[] hexData)
Returns an input stream whose bytes come from the string array
hex ,
in which the elements consist of continuous bytes of hex data. |
static java.awt.Component |
getImageObserver()
This method returns a new lightweight component suitable as an
imageObserver . |
static boolean |
isCachingEnabled()
This method returns the status of the flag that determins whether images and audio
clips are cached internally by name, as described in
setCachingEnabled . |
static java.applet.AudioClip |
loadAudioClip(java.lang.String name)
Searches the default audio clip search path for an audio clip with the specified
name and then loads it to create an
AudioClip . |
static java.applet.AudioClip |
loadAudioClip(java.lang.String name,
java.lang.String path)
Searches for an audio clip with the given name and loads it to create an
AudioClip . |
static java.awt.Image |
loadImage(java.awt.Image image)
Makes sure that the image is fully loaded before returning.
|
static java.awt.Image |
loadImage(java.lang.String name)
Searches the default image search path for an image with the specified name
and then loads it to create an
Image . |
static java.awt.Image |
loadImage(java.lang.String name,
java.lang.String path)
Searches for an image with the given name and loads it to create an
Image . |
static void |
setCachingEnabled(boolean flag)
This method sets an internal flag in the
MediaTools package to indicate
whether images and audio clips are cached internally by name. |
public static final java.lang.String DEFAULT_IMAGE_PATH
public static final java.lang.String DEFAULT_AUDIO_PATH
public static java.awt.Image loadImage(java.lang.String name)
Image
. The search process
consists of the following steps:
Image
. If so, read the image
from the resource file.
The second and third steps are repeated for each element of the image search path, which consists of a list of directories separated by colons.
Unlike the getImage
method in the Applet
class,
loadImage
waits for an image to be fully loaded before returning.
name
- The name of the imageImage
objectpublic static java.awt.Image loadImage(java.lang.String name, java.lang.String path)
Image
. Its operation is identical to the single-argument
loadImage
call except
in that this version allows the client to specify the search path
explicitly.name
- The name of the imagepath
- A string of directories names separated by colonsImage
objectpublic static java.awt.Image loadImage(java.awt.Image image)
image
- The Image
which may not yet be loadedImage
after ensuring that it is fully loadedpublic static void defineImage(java.lang.String name, java.awt.Image image)
name
- The name for the imageimage
- The image to be stored in the tablepublic static void flushImage(java.lang.String name)
name
- The name for the imagepublic static java.awt.Image createImage(int[] pixels, int width, int height)
pixels
- An array of int
representing the pixelswidth
- The width of the imageheight
- The height of the imageImage
objectpublic static java.awt.Image createImage(java.io.InputStream in)
in
- An input stream containing the dataImage
objectpublic static java.awt.Image createImage(java.lang.String[] hexData)
hexData
- A hex string array representing a .gif valueImage
objectpublic static java.applet.AudioClip loadAudioClip(java.lang.String name)
AudioClip
. The search process
consists of the following steps:
AudioClip
. If so, read the
audio clip from the resource file.
The second and third steps are repeated for each element of the audio clip search path, which consists of a list of directories separated by colons.
name
- The name of the audio clipAudioClip
objectpublic static java.applet.AudioClip loadAudioClip(java.lang.String name, java.lang.String path)
AudioClip
. Its operation is identical to the single-argument
loadAudioClip
call except
in that this version allows the client to specify the search path
explicitly.name
- The name of the audio clippath
- A string of directories names separated by colonsAudioClip
objectpublic static void defineAudioClip(java.lang.String name, java.applet.AudioClip clip)
name
- The name for the audio clipclip
- The audio clip to be stored in the tablepublic static void flushAudioClip(java.lang.String name)
name
- The name for the audio clippublic static java.applet.AudioClip createAudioClip(java.io.InputStream in)
in
- An input stream containing the dataAudioClip
objectpublic static java.applet.AudioClip createAudioClip(java.lang.String[] hexData)
hexData
- A hex string array representing an audio clipAudioClip
objectpublic static java.io.InputStream getHexInputStream(java.lang.String[] hexData)
hex
,
in which the elements consist of continuous bytes of hex data.hexData
- An array of strings specifying a byte stream coded in hexpublic static void setCachingEnabled(boolean flag)
MediaTools
package to indicate
whether images and audio clips are cached internally by name. This flag is enabled
by default, which gives better performance when clients load the same named image
more than once. It does, however, tie up memory, making it unavailable to the
garbage collector. Applications that make extensive use of memory should disable
this flag by calling setCachingEnabled(false)
.flag
- true
to enable caching by name, false
to disable it.public static boolean isCachingEnabled()
setCachingEnabled
.true
if caching by name is enabled, false
otherwise.public static java.awt.Component getImageObserver()
imageObserver
.imageObserver
.public static void beep()