日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 音频播放器_JAVA音频播放器问题

發布時間:2024/1/8 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 音频播放器_JAVA音频播放器问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼如下,請高手幫忙解決importjava.applet.*;importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjava.net.URL;importjavax.swing.*;classMyJFrameextendsJFrameimple...

代碼如下,請高手幫忙解決

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.URL;

import javax.swing.*;

class MyJFrame extends JFrame implements ActionListener

{

JButton bt1,bt2,bt3,bt4;

JPanel p1;

AudioClip ac;

MyJFrame()

{

this.setTitle("音樂播放器"); //標題

this.setSize(300,400);

p1=new JPanel();

p1.setLayout(new FlowLayout());

bt1=new JButton("打開");

bt1.addActionListener(this);

bt2=new JButton("播放");

bt2.addActionListener(this);

bt3=new JButton("循環");

bt3.addActionListener(this);

bt4=new JButton("停止"); //增加四按鈕

bt4.addActionListener(this);

p1.add(bt1);

p1.add(bt2);

p1.add(bt3);

p1.add(bt4);

this.add(p1);

this.setVisible(true);

this.addWindowListener(new WL()); //窗口監聽

}

public void actionPerformed(ActionEvent e)

{

File fl,f2; //兩個文件對象

String fpath,fname; //分別得到文件所在文件夾和文件名

URL url=null;

Applet ap=new Applet(); //定義Applet對象,調用其getAudioClip函數得到音頻

if(e.getActionCommand()=="打開") //運用文件選擇器

{

JFileChooser jfc = new JFileChooser();

if(jfc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)

{

fl=jfc.getSelectedFile(); //得到所選的文件

f2=fl.getParentFile(); //得到上級目錄文件

fpath=f2.getAbsolutePath(); //得到上級目錄地址

fname=fl.getName(); //得到文件名

try{

url=new URL("file://"+fpath); //把上級目錄地址轉化成URL對象

ac=ap.getAudioClip(url, fname); //通過Applet對象得到音頻

}catch(IOException ex){}

}

}

if(e.getActionCommand()=="播放")

{

ac.play();

}

if(e.getActionCommand()=="循環")

{

ac.loop();

}

if(e.getActionCommand()=="停止")

{

ac.stop();

}

}

class WL extends WindowAdapter

{

public void windowClosing(WindowEvent e)

{

System.exit(1);

}

}

}

public class Music {

public static void main(String[] args) {

new MyJFrame();

}

}

就是打開的時候有錯誤,也播放不了

就是AudioClip 對象ac沒有得到音頻,請問如何解決呢?謝謝了!

展開

總結

以上是生活随笔為你收集整理的java 音频播放器_JAVA音频播放器问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。