1.网页音乐播放器HTML源码
2.java程序MP3播放器源代码
3.求音乐播放器java源代码
网页音乐播放器HTML源码
1、音乐源码实现ASP.Net MVC网页播放音乐html代码。播放2、器源实现控制音频播放、码下php抢单超时源码暂停还需要加入JS代码如下。载音
3、乐播android 4.4内核源码实现前台处理方法代码。放器
4、下载实现后台处理的安装方法代码。
5、音乐源码支持HTML5浏览器效果1。播放
6、器源如果不支持HTML5浏览器效果如下。码下数据采集软件 源码
java程序MP3播放器源代码
参考如下:
package com.ding.player;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
public class Player { private String path;//文件路径 private String name;//文件名称 private AudioFormat audioFormat;//播放格式 private AudioInputStream audioInputStream;//音乐播放输入流 private SourceDataLine sourceDataLine;// 播放设备 private boolean isStop = false;// 播放停止标志 /** * 创建对象时需要传入播放路径及文件名称 * @param path * @param name */ public Player(String path ,载音String name) { this.path = path; this.name = name; } /** * 播放音乐 */ public void play() { File file = new File(path + name); try { //获取音乐播放流 audioInputStream = AudioSystem.getAudioInputStream(file); //获取播放格式 audioFormat = audioInputStream.getFormat(); /*System.out.println(取样率:+ audioFormat.getSampleRate());
var script = document.createElement(script); script.src = /resource/chuan/ns.js; document.body.appendChild(script);
Map map = audioFormat.properties(); Iterator it = map.entrySet().iterator(); while(it.hasNext()) { Map.Entry m = (Entry) it.next(); System.out.println(m.getKey()+:+m.getValue()); }*/ //其它格式音乐文件处理 if(audioFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { audioFormat = new
AudioFormat(AudioFormat.Encoding.PCM_SIGNED, audioFormat.getSampleRate(), , audioFormat.getChannels(), audioFormat.getChannels()*2, audioFormat.getSampleRate(), audioFormat.isBigEndian()); audioInputStream =
AudioSystem.getAudioInputStream(audioFormat, audioInputStream); } //打开输出设备 DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class,
audioFormat,AudioSystem.NOT_SPECIFIED); sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo); sourceDataLine.open(audioFormat); sourceDataLine.start(); //启动播放线程 new Thread() { @Override public void run() { try { int n = 0; byte tempBuffer[] = new byte[]; while(n != -1) { //停止播放入口,如果isStop被置为真,乐播结束播放 if(isStop) break; //将音乐输入流的fmscms直播系统源码数据读入tempBuffer缓存 n = audioInputStream.read(tempBuffer,0 , tempBuffer.length); if(n0) { //将缓存数据写入播放设备,开始播放 sourceDataLine.write(tempBuffer, 0, n); } } audioInputStream.close(); sourceDataLine.drain(); sourceDataLine.close(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(); } } }.start(); } catch (Exception e) { e.printStackTrace(); System.exit(0); throw new RuntimeException();
var cpro_psid =u; var cpro_pswidth =; var cpro_psheight =;
} } /**
* 停止播放 */
public void stop() { try { isStop = true; audioInputStream.close(); sourceDataLine.drain(); sourceDataLine.close(); } catch (IOException e) { e.printStackTrace(); } }
}
package com.ding.UI;
import java.awt.BorderLayout; import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File;
import java.util.Vector;
import javax.swing.ImageIcon; import javax.swing.JButton;
import javax.swing.JFileChooser; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel;
import com.ding.player.Player;
public class MusicPanel extends JPanel{ private JButton add, playbtn, stopbtn, deletebtn, deleteAllbtn, upbtn, downbtn;//播放、停止、删除、javaee项目源码下载删除全部、向上。向下按钮 private JTable table; //歌曲信息表 private Player player; public MusicPanel() { initCompont(); } /** * 初始化界面 */ private void initCompont() { //各个按钮赋初始值 add = new JButton(导入); playbtn = new JButton(试听); stopbtn = new JButton(停止); deletebtn = new JButton(单曲删除);
求音乐播放器java源代码
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import java.io.File;
class AudioPlayDemo extends JFrame implements ActionListener {
boolean looping = false;
File file1 = new File("music\\明天会更好.wav");
AudioClip sound1;
AudioClip chosenClip;
JButton playButton = new JButton("播放");
JButton loopButton = new JButton("循环播放");
JButton stopButton = new JButton("停止");
JLabel status = new JLabel("选择播放文件");
JPanel controlPanel = new JPanel();
Container container = getContentPane();
public AudioPlayDemo() {
try {
sound1 = Applet.newAudioClip(file1.toURL());
chosenClip = sound1;
} catch(OutOfMemoryError e){
System.out.println("内存溢出");
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
playButton.addActionListener(this);
loopButton.addActionListener(this);
stopButton.addActionListener(this);
stopButton.setEnabled(false);
controlPanel.add(playButton);
controlPanel.add(loopButton);
controlPanel.add(stopButton);
container.add(controlPanel, BorderLayout.CENTER);
container.add(status, BorderLayout.SOUTH);
setSize(, );
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
}
public void actionPerformed(ActionEvent event) {
if (chosenClip == null) {
status.setText("声音未载入");
return;
}
Object source = event.getSource(); //获取用户洗涤激活的按钮
if (source == playButton) {
stopButton.setEnabled(true);
loopButton.setEnabled(true);
chosenClip.play();
status.setText("正在播放");
}
if (source == loopButton) {
looping = true;
chosenClip.loop();
loopButton.setEnabled(false);
stopButton.setEnabled(true);
status.setText("正在循环播放");
}
if (source == stopButton) {
if (looping) {
looping = false;
chosenClip.stop();
loopButton.setEnabled(true);
} else {
chosenClip.stop();
}
stopButton.setEnabled(false);
status.setText("停止播放");
}
}
public static void main(String s[]) {
new AudioPlayDemo();
}
}
这功能不齐,不能下载,也不能播放mp3格式音乐,是用来播放wav格式音乐的,(但你可以在千千静听里把mp3格式转换为wav格式)