java调用音频文件,为什么执行提示错误
importjava.applet.Applet;importjava.applet.AudioClip;importjava.awt.Button;importjava...
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ohaoibg extends Applet implements ActionListener{
AudioClip audio;
Thread thread;
//播放按键
Button playaudio,loopaudio,stopaudio;
//包含字符串的下拉列表
Choice choice;
public final String[] audiotext = {"pop","salvation","shuffle"};
private AudioClip[] clips;
//跟踪哪些音频片段在播放
private boolean[] clipsPlaying;
public void init(){
this.setBackground(new Color(45,255,0));
this.setSize(300, 100);
choice = new Choice();
clips = new AudioClip[audiotext.length];
clipsPlaying = new boolean[audiotext.length];
for(int i=0;i<audiotext.length;i++){
choice.add(audiotext[i]);
clips[i] = getAudioClip(getCodeBase(),audiotext[i]+"f:\\mp3\\童年.mp3");//添加音频的路径和扩展名
clipsPlaying[i] = false;
}
add(choice);
playaudio = new Button("播放");
loopaudio = new Button("循环播放");
stopaudio = new Button("停止");
add(playaudio);
add(loopaudio);
add(stopaudio);
playaudio.addActionListener(this);
loopaudio.addActionListener(this);
stopaudio.addActionListener(this);
//没有音频播放时放停止按键变灰
stopaudio.setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int choiceindex = choice.getSelectedIndex();
AudioClip clipindex = clips[choiceindex];
//播放被选中的音频
if(e.getSource()==playaudio){
clipindex.play();
stopaudio.setEnabled(true);
clipsPlaying[choiceindex] = true;
}
else if(e.getSource()== loopaudio){
clipindex.loop();
stopaudio.setEnabled(true);
clipsPlaying[choiceindex] = true;
}
else if(e.getSource()==stopaudio){
clipindex.stop();
stopaudio.setEnabled(false);
clipsPlaying[choiceindex] = false;
}
}
}
以上为代码,请指点那里出错了。 展开
import java.applet.AudioClip;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ohaoibg extends Applet implements ActionListener{
AudioClip audio;
Thread thread;
//播放按键
Button playaudio,loopaudio,stopaudio;
//包含字符串的下拉列表
Choice choice;
public final String[] audiotext = {"pop","salvation","shuffle"};
private AudioClip[] clips;
//跟踪哪些音频片段在播放
private boolean[] clipsPlaying;
public void init(){
this.setBackground(new Color(45,255,0));
this.setSize(300, 100);
choice = new Choice();
clips = new AudioClip[audiotext.length];
clipsPlaying = new boolean[audiotext.length];
for(int i=0;i<audiotext.length;i++){
choice.add(audiotext[i]);
clips[i] = getAudioClip(getCodeBase(),audiotext[i]+"f:\\mp3\\童年.mp3");//添加音频的路径和扩展名
clipsPlaying[i] = false;
}
add(choice);
playaudio = new Button("播放");
loopaudio = new Button("循环播放");
stopaudio = new Button("停止");
add(playaudio);
add(loopaudio);
add(stopaudio);
playaudio.addActionListener(this);
loopaudio.addActionListener(this);
stopaudio.addActionListener(this);
//没有音频播放时放停止按键变灰
stopaudio.setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int choiceindex = choice.getSelectedIndex();
AudioClip clipindex = clips[choiceindex];
//播放被选中的音频
if(e.getSource()==playaudio){
clipindex.play();
stopaudio.setEnabled(true);
clipsPlaying[choiceindex] = true;
}
else if(e.getSource()== loopaudio){
clipindex.loop();
stopaudio.setEnabled(true);
clipsPlaying[choiceindex] = true;
}
else if(e.getSource()==stopaudio){
clipindex.stop();
stopaudio.setEnabled(false);
clipsPlaying[choiceindex] = false;
}
}
}
以上为代码,请指点那里出错了。 展开
1个回答
展开全部
没错 Mp3格式java不支持
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询