java音樂(lè)格式代碼 流行音樂(lè)代碼

java如何讀取MP3格式文件的內(nèi)容然后對(duì)其播放實(shí)例代碼

直接下個(gè)JMF,google搜,sun官網(wǎng)上有~~然后安裝目錄是你的JDK,

榮縣網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,榮縣網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為榮縣千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的榮縣做網(wǎng)站的公司定做!

再播放MP3文件就:

import javax.media.*;

import java.net.MalformedURLException;

import java.net.URL;

Player player;

File playFile=new File("");//你的MP3文件

try {

player=Manager.createRealizedPlayer(playFile.toURL());

player.prefetch();

player.setMediaTime(new Time(10.0));

player.start();

} catch (NoPlayerException e1)

{

e1.printStackTrace();

} catch (CannotRealizeException e1)

{

e1.printStackTrace();

} catch (MalformedURLException e1)

{

e1.printStackTrace();

} catch (IOException e1)

{

e1.printStackTrace();

}

這種基本代碼,自己搜一下,用編譯器熟悉熟悉JMF的方法就會(huì)了。。。我以前回答別人時(shí)的答案~~~

編寫(xiě)一個(gè)java類,實(shí)現(xiàn)mid或者wav格式的背景音樂(lè)播放,要循環(huán)的,用作一個(gè)小游戲的背景音樂(lè),謝

import?java.applet.Applet;

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()?{//循環(huán)

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()));//填寫(xiě)你自己的文件路徑

}?catch?(MalformedURLException?e)?{

e.printStackTrace();

}

mac.loop();//循環(huán)播放

}

}

跪求java 音樂(lè)播放的代碼啊,完美運(yùn)行的就行

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; //循環(huán)播放

private JButton buttinzi=null; //停止

private JButton butshan=null; //上一首

private JButton butzhantin=null; //暫停

private JButton butxia=null; //下一首

private TrayIcon trayIcon;//托盤圖標(biāo)

private SystemTray systemTray;//系統(tǒng)托盤

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("愛(ài)不再來(lái)");

box1.addItem("抽身");

box1.addItem("傷心城市");

box1.addItem("二零一二");

box1.addItem("精忠報(bào)國(guó)");

box1.addItem("秋沙");

box1.addItem("吻別");

box1.addItem("音樂(lè)瘋起來(lái)");

box1.setBounds(10,20,150,20);

butbofan=new JButton("播放");

butbofan.addActionListener(this);

butbofan.setBounds(165,50,60,20);

butboxhuan=new JButton("循環(huán)播放");

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();//獲得系統(tǒng)托盤的實(shí)例

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

try {

trayIcon = new TrayIcon(ImageIO.read(new File("004.jpg")));

systemTray.add(trayIcon);//設(shè)置托盤的圖標(biāo),0.gif與該類文件同一目錄

}

catch (IOException e1)

{

e1.printStackTrace();

}

catch (AWTException e2)

{

e2.printStackTrace();

}

this.addWindowListener(

new WindowAdapter(){

public void windowIconified(WindowEvent e)

{

dispose();//窗口最小化時(shí)dispose該窗口

}

});

trayIcon.addMouseListener(new MouseAdapter()

{

public void mouseClicked(MouseEvent e){

if(e.getClickCount() == 2)//雙擊托盤窗口再現(xiàn)

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("內(nèi)存溢出");

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("內(nèi)存溢出");

er.printStackTrace();

} catch(Exception ex){

ex.printStackTrace();

}

looping = true;

chosenClip.loop();

butboxhuan.setEnabled(false);

buttinzi.setEnabled(true);

butzhantin.setText("暫停");

this.setTitle("正在循環(huán)播放"+(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("繼續(xù)");

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

}

*/

java應(yīng)用程序中播放mid音樂(lè)的代碼,求助?。。?!

import sun.audio.*;

import java.io.*;

import java.awt.*;

import java.awt.event.*;

class Sound5

{

FileInputStream file;

BufferedInputStream buf;

public Sound5()

{

try

{

file=new FileInputStream("1.mid");

buf=new BufferedInputStream(file);

AudioStream audio=new AudioStream(buf);

AudioPlayer.player.start(audio);

}

catch (Exception e) {}

}

}

public class e8165 extends Frame implements ActionListener

{

e8165()

{

super("音頻播放器");

setBounds(300,300,200,100);

setVisible(true);

Button btn=new Button("播放");

setLayout(new FlowLayout());

add(btn);

btn.addActionListener(this);

validate();

// Sound5 play = new Sound5();

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e)

{ System.exit(1); }

});

}

public void actionPerformed(ActionEvent e)

{

Sound5 play = new Sound5();

}

public static void main(String[] args)

{

new e8165();

}

}

//下載一個(gè).mid文件命名為1,放在上述代碼的包下

分享題目:java音樂(lè)格式代碼 流行音樂(lè)代碼
轉(zhuǎn)載源于:http://www.muchs.cn/article36/doocepg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)App設(shè)計(jì)、網(wǎng)站改版、面包屑導(dǎo)航域名注冊(cè)、動(dòng)態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)