音乐剪辑java代码 java编曲( 四 )


import java.applet.AudioClip;
import java.net.MalformedURLException;
public class MusicAudioClip {
AudioClip clip = null;
public AudioClip getAudioClip() {
return this.clip;
}
public void setAudioClip(AudioClip clip) {
this.clip = clip;
}
public void play() {//播放
if (getAudioClip() != null) {
getAudioClip().play();
}
}
public void loop() {//循环
if (getAudioClip() != null) {
getAudioClip().loop();
}
}
public void stop() {//停止
if (getAudioClip() != null) {
getAudioClip().stop();
}
}
public static void main(String[] args) {
MusicAudioClip mac = new MusicAudioClip();
try {
mac.setAudioClip(Applet
.newAudioClip((new java.io.File("music\\0.wav")).toURL()));//填写音乐剪辑java代码你自己音乐剪辑java代码的文件路径
} catch (MalformedURLException e) {
e.printStackTrace();
}
mac.loop();//循环播放
}
}
跪求java 音乐播放的代码啊 , 完美运行的就行import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.AWTException;
import java.awt.Frame;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class bofan_2 extends JFrame implements ActionListener
{
boolean looping=false;
File file1=null;
AudioClip sound1;
AudioClip chosenClip;
private JComboBox box1=null;//歌曲列表
private JButton butbofan=null;//播放
private JButton butboxhuan=null; //循环播放
private JButton buttinzi=null;//停止
private JButton butshan=null;//上一首
private JButton butzhantin=null; //暂停
private JButton butxia=null;//下一首
private TrayIcon trayIcon;//托盘图标
private SystemTray systemTray;//系统托盘
public bofan_2()
{
this.setSize(420,400);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setLayout(null);
box1=new JComboBox();
box1.addItem("伤心太平洋");
box1.addItem("劲爆的士高");
box1.addItem("老夫少妻");
box1.addItem("爱不再来");
box1.addItem("抽身");
box1.addItem("伤心城市");
box1.addItem("二零一二");
box1.addItem("精忠报国");
box1.addItem("秋沙");
box1.addItem("吻别");
box1.addItem("音乐疯起来");
box1.setBounds(10,20,150,20);
butbofan=new JButton("播放");
butbofan.addActionListener(this);
butbofan.setBounds(165,50,60,20);
butboxhuan=new JButton("循环播放");
butboxhuan.addActionListener(this);
butboxhuan.setBounds(230,50,90,20);
buttinzi=new JButton("停止");
buttinzi.setEnabled(false);
buttinzi.addActionListener(this);
buttinzi.setBounds(335,50,60,20);
butshan=new JButton("上一首");
butshan.addActionListener(this);
butshan.setBounds(165,90,80,20);
butzhantin=new JButton("暂停");
butzhantin.setEnabled(false);
butzhantin.addActionListener(this);
butzhantin.setBounds(250,90,60,20);
butxia=new JButton("下一首");
butxia.addActionListener(this);
butxia.setBounds(320,90,80,20);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(box1);
this.getContentPane().add(butbofan);
this.getContentPane().add(butboxhuan);
this.getContentPane().add(buttinzi);
this.getContentPane().add(butshan);

推荐阅读