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();
}
}