Hvilkte lydformater kan afspilles via java?
Jeg har lavet en lille applet (efter en java begynder bog), som viser en billede og looper et lydklip. Men jeg får følgende fejl når jeg vil afvikle min applet:NativeAudioStream: invalid sample rate of 44100.
Got IOException fetching sound: sun.audio.InvalidAudioFormatException: InvalidAudioFormatException
sun.audio.InvalidAudioFormatException: InvalidAudioFormatException
at sun.audio.NativeAudioStream.<init>(NativeAudioStream.java)
at com.apple.mrj.JManager.ULAWAudioBuffer.run(JMAppletAudioClipOld.java)
at java.lang.Thread.run(Thread.java)
Jeg har forsøgt alle mulige formater til min lyd fil (diverse sample rates, PCM eller ULAW compression, .au eller .aif, mono eller stereo, men den vil ikke acceptere formatet.)
her følger source koden:
// IMGSound
//
// Description:
// ImgSound is an applet that diplays an image and plays a sound
// when the applet starts.
import java.awt.*;
import java.applet.*;
import java.net.*;
public class ImgSound extends java.applet.Applet
{
// URLs
private String img_url = null;
private String sound_url = null;
// Panels and canvases that the applet uses
Canvas c_north = null;
// Images that the applet uses
Image img_1 = null;
// Sounds that the applet uses
AudioClip sound_clip = null;
// The background color
Color bkgnd;
public void init()
{
// Set up the display
setLayout(new BorderLayout());
bkgnd = new Color(255,255,255); // White
setBackground(bkgnd);
c_north = new Canvas();
add (\"North\", c_north);
// Read the parameters from the HTML document
img_url = getParameter(\"picture-url\");
sound_url = getParameter(\"sound-url\");
// Load image and sound clip
MediaTracker tracker = new MediaTracker(this);
img_1 = getImage(getCodeBase(), img_url);
tracker.addImage(img_1, 0);
try
{ tracker.waitForID(0); }
catch (InterruptedException e)
{ System.out.println(\"Image Load Failure\"); }
sound_clip = getAudioClip(getCodeBase(), sound_url);
}
public void start()
{
// Play the sound over and over
sound_clip.loop();
}
public void stop()
{
// Quiet
sound_clip.stop();
}
public void paint(Graphics g)
{
if (img_1 != null)
{
g.drawImage(img_1, 0, 0, getBackground(), c_north);
}
}
public boolean keyDown(Event evt, int key)
{
// Quiet
sound_clip.stop();
return true;
}
}
