JAVA播放音频的一些问题
importjava.applet.*;importjava.net.URL;importjavax.swing.*;publicclassasdasdsaextends...
import java.applet.*;
import java.net.URL;
import javax.swing.*;
public class asdasdsa extends JApplet{
private AudioClip audioClip;
public asdasdsa(){
URL url1=getClass().getResource("image/us.jpg");
add(new JLabel(new ImageIcon(url1)));
URL url=getClass().getResource("audio/1231.mid");
audioClip=Applet.newAudioClip(url);
audioClip.loop();
}
public void start(){
if(audioClip != null)
audioClip.loop();
}
public void stop(){
if(audioClip != null) audioClip.stop();
}
}
老是出现未初始化小程序
求高手指教 展开
import java.net.URL;
import javax.swing.*;
public class asdasdsa extends JApplet{
private AudioClip audioClip;
public asdasdsa(){
URL url1=getClass().getResource("image/us.jpg");
add(new JLabel(new ImageIcon(url1)));
URL url=getClass().getResource("audio/1231.mid");
audioClip=Applet.newAudioClip(url);
audioClip.loop();
}
public void start(){
if(audioClip != null)
audioClip.loop();
}
public void stop(){
if(audioClip != null) audioClip.stop();
}
}
老是出现未初始化小程序
求高手指教 展开
2013-11-18
展开全部
调用的文件的路径问题,us.jpg和1231.mid所在的文件夹放在生成的class文件所在目录下,不然不能调用。我已经测试通过,代码改了下。参考下面代码:
import java.applet.*;
import java.net.URL;
import javax.swing.*;
public class asdasdsa extends JApplet {
private AudioClip audioClip;
public asdasdsa() {
URL url1 = getClass().getResource("image/us.jpg");
add(new JLabel(new ImageIcon(url1)));
URL url = getClass().getResource("audio/1231.mid");
audioClip = Applet.newAudioClip(url);
audioClip.loop();
}
@Override
public void start() {
if (audioClip != null) {
audioClip.loop();
}
}
@Override
public void stop() {
if (audioClip != null) {
audioClip.stop();
}
}
}
import java.applet.*;
import java.net.URL;
import javax.swing.*;
public class asdasdsa extends JApplet {
private AudioClip audioClip;
public asdasdsa() {
URL url1 = getClass().getResource("image/us.jpg");
add(new JLabel(new ImageIcon(url1)));
URL url = getClass().getResource("audio/1231.mid");
audioClip = Applet.newAudioClip(url);
audioClip.loop();
}
@Override
public void start() {
if (audioClip != null) {
audioClip.loop();
}
}
@Override
public void stop() {
if (audioClip != null) {
audioClip.stop();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询