十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
/**下载jar包:
成都创新互联公司专注于丰南企业网站建设,自适应网站建设,成都商城网站开发。丰南网站建设公司,为丰南等地区提供建站服务。全流程按需网站开发,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务
*/
import java.io.BufferedInputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javazoom.jl.player.Player;
public class MP3Online {
private String filename;
private Player player;
private HttpURLConnection connection;// 存储连接
private int downed = 0;// 文加已下载大小,初始值为0
private URL fileurl;// 记录要下载文件的地址
// constructor that takes the name of an MP3 file
public MP3Online(String filename) {
this.filename = filename;
}
public void close() {
if (player != null)
player.close();
}
// play the MP3 file to the sound card
public void play() {
try {
fileurl = new URL(filename);
connection = (HttpURLConnection) fileurl.openConnection();
connection.setRequestProperty("Range", "byte=" + this.downed + "-");
BufferedInputStream bis = new BufferedInputStream(connection
.getInputStream());
player = new Player(bis);
} catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
// run in new thread to play in background
new Thread() {
public void run() {
try {
player.play();
} catch (Exception e) {
System.out.println(e);
}
}
}.start();
}
// test client
public static void main(String[] args) {
// String filename = "F:\\Workspaces\\glxt2\\test\\simple\\fallin-alicia keys.mp3";
String filename = "";
MP3Online mp3 = new MP3Online(filename);
mp3.play();
// when the computation is done, stop playing it
mp3.close();
// play from the beginning
mp3 = new MP3Online(filename);
mp3.play();
}
}
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);
this.getContentPane().add(butzhantin);
this.getContentPane().add(butxia);
try {
UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}
setSize(450,450);
systemTray = SystemTray.getSystemTray();//获得系统托盘的实例
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
trayIcon = new TrayIcon(ImageIO.read(new File("004.jpg")));
systemTray.add(trayIcon);//设置托盘的图标,0.gif与该类文件同一目录
}
catch (IOException e1)
{
e1.printStackTrace();
}
catch (AWTException e2)
{
e2.printStackTrace();
}
this.addWindowListener(
new WindowAdapter(){
public void windowIconified(WindowEvent e)
{
dispose();//窗口最小化时dispose该窗口
}
});
trayIcon.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2)//双击托盘窗口再现
setExtendedState(Frame.NORMAL);
setVisible(true);
}
});
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source== butbofan)
{
System.out.println((String) box1.getSelectedItem());
file1=new File((String) box1.getSelectedItem()+".wav");
butboxhuan.setEnabled(true);
buttinzi.setEnabled(true);
butzhantin.setEnabled(true);
butzhantin.setText("暂停");
try {
sound1 = Applet.newAudioClip(file1.toURL());
chosenClip = sound1;
} catch(OutOfMemoryError er){
System.out.println("内存溢出");
er.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
chosenClip.play();
this.setTitle("正在播放"+(String) box1.getSelectedItem());
}
if (source== butboxhuan)
{
file1=new File((String) box1.getSelectedItem()+".wav");
try {
sound1 = Applet.newAudioClip(file1.toURL());
chosenClip = sound1;
} catch(OutOfMemoryError er){
System.out.println("内存溢出");
er.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
looping = true;
chosenClip.loop();
butboxhuan.setEnabled(false);
buttinzi.setEnabled(true);
butzhantin.setText("暂停");
this.setTitle("正在循环播放"+(String) box1.getSelectedItem());
}
if (source== buttinzi)
{
if (looping)
{
looping = false;
chosenClip.stop();
butboxhuan.setEnabled(true);
butzhantin.setText("暂停");
} else {
chosenClip.stop();
}
buttinzi.setEnabled(false);
this.setTitle("停止播放");
}
if(source==butshan)
{
butzhantin.setText("暂停");
}
if(source==butzhantin)
{
buttinzi.setEnabled(false);
butzhantin.setText("继续");
if(source==butzhantin)
{
butzhantin.setText("暂停");
}
}
if(source==butxia)
{
butzhantin.setText("暂停");
}
}
public static void main(String[] args)
{
bofan_2 xx=new bofan_2();
}
}
/*
可以用加载声音文件的方法:
第一帧:mysound= new Sound();
mysound.attachSound(声音id名字);
ptime = 0;
播放按钮as:
on(release){
mysound.start(ptime);
}
暂停按钮as:
on(release){
ptime = mysound.position/1000;
mysound.stop();
}
*/
试试看在body中输入这段代码:script type="text/javascript"
var pageTracker = _gat._getTracker("UA-3689486-1");
pageTracker._initData();
pageTracker._trackPageview();
pagePublicTracker = _gat._getTracker("UA-10197155-1");
pagePublicTracker._initData();
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F350e824b48b2d02f8a8d11e138ce53a8' type='text/javascript'%3E%3C/script%3E"));
/script
打开系统记事本,按如下结构编辑一个文档,退出保存,修改其扩展名为.wmv
ASX version="3.0"
Entry
Title歌曲名/Title
Author作者/Author
Copyright版权/Copyright
Banner href="你的个性图片在网络中的地址"/Banner
Ref href="以http或mms开头以mp3/wma/wmv/wav/midi/mpg/mpeg/avi结尾的视频音频地址"/
/Entry
ENTRYREF HREF="音乐地址1"//ENTRY
ENTRYREF HREF="音乐地址2"//ENTRY
这里可以随便添加曲目.....
ENTRYREF HREF="音乐地址10"//ENTRY
/ASX
将上面保存的.wmv文件上传到internet有效空间.这里推荐使用google pages ,它是免费的100M主页空间,现在只要有google帐号就可以激活.(若不想这样麻烦,可以申请放到我的空间内--年费40$免月租)
将编辑的.wmv文件的网上地址赋值到Power Toy,保存.完成.
实现机理:
ASX文件是一个文本文件,主要用途是对流信息重定向.
在ASX中包含了媒体内容对应的URL,当我们在HTML中让一个HYPERLINK与ASX联系时,浏览器会直接将ASX的内容送给MEDIA PLAYER,MEDIA PLAYER 会根据ASX文件的信息用相应的协议去打开指定位置上的多媒体信息流或多媒体文件。
利用ASX文件来重定向流信息的原因主要是:目前通用的浏览器通常均不能直接支持用于播放流信息的协议MMS,所以我们采用ASX文件。
采用ASX文件以后,当浏览器发现一个连接与ASX有关时,它知道需要用MEDIA PLAYER 来播放流信息,于是它就会启动MEIDA PLAYER,MEDIA PLAYER就可以用MMS协议来播放流信息了。