A. 求音乐播放器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(300, 130);
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格式)
B. java版的千千静听和酷狗
很肯定的告诉你不能!java版本不支持调用除MID格式以外的音频
C. java题目,做一个音乐播放器
android项目吧
D. 求java声音代码,可以播mp3的谢谢了!最好写一下!
目前java只能播放au,aiff,wav,midi,rfm格式的音频,如果是mp3格式的文件,你可以格式转化一下,用千千静听就可以转化成wav格式的音频文件。
我写的示例代码:
1、Applet
import java.awt.*;
import java.applet.* ;
public class Sound extends Applet
{
/**
*
*/
private static final long serialVersionUID = 1L;
public void paint(Graphics g)
{
AudioClip audioClip=getAudioClip(getCodeBase(),"NewStories.wav");
//创建AudioClip对象并用getAudioClip方法将其初始化
g.drawString("Sound Demo!",5,15);
audioClip.play();//使用AudioClip类的play方法播放音乐
}
}
2、html
<html>
<title>SoundDemo Applet</title>
<applet code="Sound.class" width="300" height="200">
</applet>
</html>
注意将音频文件放在class文件同一目录下,先编译Sound.java文件,然后运行html文件就能运行该Applet了!
E. 找一款java手机mp3播放器软件
可以下载千千静听,音乐泡泡,GG
Music等软件,千千静听有触摸版的,在手机之家可以下载
F. java能调用“千千静听”可以实现“暂停”“下一首”的操作吗
没试过,只尝试过用C。可以的
G. java写mp3播放器的问题
呵呵,要用到JMF包啊,到网上下载一个JMF包,照着说明安装上。
以下是我写的一个很简单的播放器,只能播放mp3,mpeg,mpg,wav等简单的格式。
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.MediaLocator;
import javax.media.RealizeCompleteEvent;
import javax.media.bean.playerbean.MediaPlayer;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.JList;
import java.awt.BorderLayout;
import javax.swing.JSplitPane;
import java.awt.Component;
import java.util.Vector;
public class JMF_T extends JFrame implements ControllerListener, ActionListener {
MediaPlayer Player;
private String filename = "";
private static final long serialVersionUID = 1L;
private Vector vct = new Vector(); // @jve:decl-index=0:
private JPanel jContentPane = null;
private JSplitPane jSplitPane = null;
private JPanel playPanel = null;
private JList jList = null;
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setDividerSize(5);
jSplitPane.setResizeWeight(0.8);
jSplitPane.setRightComponent(getJList());
jSplitPane.setLeftComponent(getPlayPanel());
}
return jSplitPane;
}
private JPanel getPlayPanel() {
if (playPanel == null) {
playPanel = new JPanel();
playPanel.setLayout(new BorderLayout());
}
return playPanel;
}
private JList getJList() {
if (jList == null) {
jList = new JList();
jList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
// TODO Auto-generated Event stub mouseClicked()
if (e.getClickCount() == 1) {
String str = (String) jList.getSelectedValue();
if (str == null) {
return;
}
filename = str;
System.out.println(str);
}
if (e.getClickCount() == 2) {
String str = (String) jList.getSelectedValue();
if (str == null) {
return;
}
filename = str;
play();
}
}
});
}
return jList;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JMF_T thisClass = new JMF_T();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public JMF_T() {
initialize();
}
private void OpenFile() {
FileDialog fd = new FileDialog(this, "Choose Video", FileDialog.LOAD);
fd.setVisible(true);
filename = fd.getDirectory() + fd.getFile();
System.out.println(filename);
if (filename.equals("")) {
return;
} else if (filename.equals("nullnull")) {
return;
}
boolean j = false;
for (int i = 0; i < vct.size(); i++) {
if (vct.get(i).toString().equals(filename)) {
j = true;
break;
}
}
if (j == false) {
vct.add(filename);
jList.setListData(vct);
}
}
private void stop() {
if (Player != null) {
Player.stop();
Player.deallocate();
}
}
private void play() {
try {
if (filename.equals("")) {
return;
}
if (Player == null) {
Player = new MediaPlayer();
} else {
closePreviosPlayer();
}
Player.setMediaLocator(new MediaLocator("file:///" + filename));
Player.addControllerListener(this);
Player.realize();
Player.start();
} catch (Exception e) {
}
}
public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand().toString();
if (action.equals("Open")) {
OpenFile();
}
if (action.equals("Play")) {
play();
}
if (action.equals("Stop")) {
stop();
}
if (action.equals("Exit")) {
dispose();
System.exit(0);
}
}
private void initialize() {
this.setSize(500, 350);
setLocation(300, 100);
this.setContentPane(getJContentPane());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu fileMenu = new Menu("File");
Menu actMenu = new Menu("Action");
mb.add(fileMenu);
mb.add(actMenu);
MenuItem itemOpen = new MenuItem("Open");
itemOpen.addActionListener(this);
fileMenu.add(itemOpen);
fileMenu.addSeparator();
MenuItem itemPlay = new MenuItem("Play");
itemPlay.addActionListener(this);
actMenu.add(itemPlay);
actMenu.addSeparator();
MenuItem itemStop = new MenuItem("Stop");
itemStop.addActionListener(this);
actMenu.add(itemStop);
MenuItem itemExit = new MenuItem("Exit");
itemExit.addActionListener(this);
fileMenu.add(itemExit);
this.validate();
this.setVisible(true);
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJSplitPane(), BorderLayout.CENTER);
}
return jContentPane;
}
private void closePreviosPlayer() {
if (Player == null)
return;
Player.stop();
Player.deallocate(); // 停止播放并且重新装载DateSource
Component visual = Player.getVisualComponent();
Component control = Player.getControlPanelComponent();
if (visual != null) {
playPanel.remove(visual);
}
if (control != null) {
playPanel.remove(control);
}
}
public synchronized void controllerUpdate(ControllerEvent event) {
if (event instanceof RealizeCompleteEvent) {
Component comp;
if ((comp = Player.getControlPanelComponent()) != null) {
playPanel.add("South", comp);
} else {
closePreviosPlayer();
}
if ((comp = Player.getVisualComponent()) != null) {
playPanel.add("Center", comp);
}
validate();
}
}
}
还有啊,初学者不写代码怎么学啊?写多了理解的自然就深了。
H. 山寨诺基亚N8 480X800的全触摸屏 求一个JAVA能用的音乐播放器。。。
你那手机是山寨的,那也就是,不是塞班系统了。
就是单纯的山寨手机系统 按道理是安装不了 QQ音乐,千千静听 之类的播放器。
你只能用本手机自带的播放器听歌了。
I. java简单仿飞秋项目源代码
又是一个找苦力的。。。
J. 如何用Java实现在线听音乐
/**下载jar包:
http://www.javazoom.net/javalayer/sources/jlayer1.0.1.zip
*/
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 = "http://www.venusad.cn/venus/ch/mp3/01.mp3";
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();
}
}