Java AudioClip에 대한 이전 호를 읽었으며 조사를 마쳤습니다. 아직까지는 AudioClip이 재생되지 않습니다. .wav 클립은 Eclipse IDE에서 제대로 작동하지만 적절한 디렉토리에도 있습니다. 파일 이 잘못된 디렉토리에 있으면이 코드 단편은 오류 메시지를 표시합니다.Java AudioClip - 소리가 나지 않습니다. 오류가 없습니다.
내 교수는
audioClip = Applet.newAudioClip(new File(filePath).toURI().toURL());
이 경우에는 호출되지 NO SOUND됩니까 하단에있는 놀이 방법을 실행, 우리는이 형식을 사용하여의 AudioClip을한다는 것을 물었다! 도움이 될 것입니다.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.net.MalformedURLException;
public class PlaySoundApplet extends Applet implements ActionListener
{
private static final long serialVersionUID = 1L;
Button play,stop;
AudioClip audioClip;
public void init()
{
play = new Button("Play");
add(play);
play.addActionListener(this);
stop = new Button("Stop");
add(stop);
stop.addActionListener(this);
try
{
String filePath = "." + File.separator + "audio" + File.separator + "island_music.wav";
File file = new File(filePath);
if (file.exists())
{
audioClip = Applet.newAudioClip(file.toURI().toURL());
}
else
{
throw new RuntimeException("Directory " + filePath + " does not exist"); //debugging
}
}
catch (MalformedURLException malformedURLException)
{
throw new RuntimeException("Malformed URL: " + malformedURLException); //debugging
}
}
public void actionPerformed(ActionEvent ae)
{
Button source = (Button)ae.getSource();
if (source.getLabel() == "Play")
{
audioClip.play();
System.out.println("Play was executed");
}
else if(source.getLabel() == "Stop")
{
audioClip.stop();
System.out.println("Stop was executed");
}
}
}
* "소리는 들리지 않지만 소리가 나지 않습니다!"* 외쳐서는 안됩니다! 간단한 ['leftright.wav'] (http://pscode.org/media/#sound) 코드를 사용해보십시오. 귀하의 숙제는 이것이 애플릿이어야 함을 명시합니까? –
와우 ... 왼쪽 .wav 작품! 그래서 나는 .wav 파일의 다른 유형을 시도해야 할 것 같아요? –