导航:首页 > 编程语言 > javawav文件

javawav文件

发布时间:2022-09-20 09:49:10

java播放WAV文件找不到import sun.audio.AudioPlayer;

jdk里面没有sun.audio.AudioPlayer这个东东,是三方包的话,如果没设定好环境变量,没将这东西放到环境变量里面,当然找不到了。

WAV用jdk包javax.sound.sampled里面的东西就可以了。参考例子:
http://hi..com/breezedancer/blog/item/7eebb499680d8f086e068cb9.html

Ⅱ 求教JAVA高手,怎样调用电脑上的wav格式文件并播放播放声音不会断断续续的,谢谢!!

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.border.Border;
public class testmusic {
// static String s1="E:\\nine muses - no playboy - 韩国.wav";
// static String s2="E:\\蔡妍 - my love.wav";
// static String s3="E:\\钢琴与嗨曲的完美结合 性感女声慢摇 经典中的经典.wav";
public static void main(String[] args){
test t = new test();
Thread s = new Thread(t);
s.start();
}
}
class AePlayWave extends Thread{
private String filename;
public AePlayWave(String wavfile){
filename = wavfile;
}
public void run(){
File soundFile = new File(filename);
AudioInputStream audioInputStream=null;
try{
audioInputStream = AudioSystem.getAudioInputStream

(soundFile);
}catch(Exception e1){
e1.printStackTrace();
return;
}
AudioFormat format = audioInputStream.getFormat();
SourceDataLine auline = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class,format);
try{
auline=(SourceDataLine)AudioSystem.getLine(info);
auline.open(format);
}catch(Exception e){
e.printStackTrace();
return;
}
auline.start();
int nBytesRead=0;
byte[] abData = new byte[1024];
try{
while(nBytesRead!=-1){
nBytesRead=audioInputStream.read

(abData,0,abData.length);
if(nBytesRead>=0)
auline.write(abData,0,nBytesRead);
}
}catch(IOException e){
e.printStackTrace();
return;
}finally{
auline.drain();
auline.close();
}
}
}
//import java.io.File;
//import javax.sound.sampled.AudioFormat;
//import javax.sound.sampled.AudioInputStream;
//import javax.sound.sampled.AudioSystem;
//import javax.sound.sampled.Clip;
//import javax.sound.sampled.DataLine;
//try{
//File file = new File("D:\\music\\i - m - back.mp3");
//AudioInputStream stream = AudioSystem.getAudioInputStream(file);
//AudioFormat format = stream.getFormat();
//DataLine.Info info = new DataLine.Info(Clip.class,format);
//Clip clip = (Clip)AudioSystem.getLine(info);
//clip.open(stream);
//clip.start();
//}catch(Exception e){
//e.printStackTrace();
//}
class test extends JFrame implements Runnable,ActionListener{
int x=30,y=40;
JMenuBar jmb= null;
JMenu jm = null;
JMenuItem jmi,jmi1,jmi2=null;
test(){
super("JAVA写的最原始的WAV格式音乐播放器");
setSize(500,500);
jmb=new JMenuBar();
jm = new JMenu("文件");
jmi = new JMenuItem("播放");
jmi1= new JMenuItem("打开");
jmi2=new JMenuItem("退出");
this.setLayout(new BorderLayout());
this.add(jmb,BorderLayout.NORTH);
jmb.add(jm);
jm.add(jmi);
jm.add(jmi1);
jm.add(jmi2);
jmi1.addActionListener(this);
jmi2.addActionListener(this);
jmi1.setActionCommand("open");
jmi2.setActionCommand("exit");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
this.getContentPane().setBackground(Color.black);
}

@Override
public void run() {
// TODO Auto-generated method stub
while(true){
try{
Thread.sleep(1000);
x+=10;
y+=10;
repaint();
if(x==500){
x=30;
}
if(y==500){
y=40;
}
}catch(Exception e){
e.printStackTrace();
}
}
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.red);
g.fillOval(x,y,40,40);
g.fill3DRect(y+60,x+60,60,60,true);
g.setColor(Color.yellow);
g.setFont(new Font("华文彩云",Font.BOLD,20));
g.drawString("点击菜单条的打开选中你电脑里面的WAV格式音乐", 20, 300);
g.drawString("点击退出即可退出",20,330);
g.drawString("别的按钮没有注册监听,无效。。。。",20,350);
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand().equals("open")){
JFileChooser jf = new JFileChooser();
jf.showOpenDialog(null);
String s1=(jf.getSelectedFile().getAbsoluteFile()).toString();
//System.out.println(s1);
AePlayWave a = new AePlayWave(s1);
a.start();
}
if(e.getActionCommand().equals("exit")){
System.exit(0);
}
}
}
仅支持WAV格式 点击打开按钮播放

Ⅲ java实现 mp3格式转换wav

Ⅳ java 怎么合并两个wav文件

//帮你写了一个,是两个mp3文件的合并
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
/**
*把两个.mp3文件合并成一个.mp3文件
*
*@authorwangran
*
*/
publicclassMerger{
publicMerger(){
}
publicstaticvoidmain(String[]args){
FileInputStreamfis=null;
FileOutputStreamfos=null;
BufferedInputStreambis=null;
BufferedOutputStreambos=null;
//源文件
Filein1=newFile("D:/杂/娱乐/音乐/hero.mp3");
Filein2=newFile("D:/杂/娱乐/音乐/carelesswhisper.mp3");

//目标文件
Fileout=newFile("D:/music2.mp3");

//进行流操作
try{
fis=newFileInputStream(in1);
fos=newFileOutputStream(out,true);
bis=newBufferedInputStream(fis);
bos=newBufferedOutputStream(fos);
intlen;
byte[]buf=newbyte[1024];
while((len=bis.read(buf))!=-1){
bos.write(buf,0,len);
}
bos.flush();
fis=newFileInputStream(in2);
bis=newBufferedInputStream(fis);
while((len=bis.read(buf))!=-1){
bos.write(buf,0,len);
}
bos.flush();
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}finally{
//关闭流
if(bis!=null)
try{
bis.close();
}catch(IOExceptione){
e.printStackTrace();
}
if(bos!=null)
try{
bos.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
}

Ⅳ JAVA中如何解析WAV文件,有具体代码么WAV文件存放数据具体是哪个字段

JMF框架 Java Media Frame 是SUN公司出的解析多媒体的框架

说明文档很多 自己去网络查吧 提醒你下 这个东东很不常用 还不如用。NET解析 因为C#里面的标准库里面就包含解析多媒体的API了

Ⅵ java 代码是否可以实现把wav 文件转成 mp3 的呢

JAVE官方的jar包带了ffmpeg的exe程序,所以在windows上可以直接使用,
但是如果要在Linux上用就得先把ffmpeg的环境装好。

Filesource=newFile("source.wav");
Filetarget=newFile("target.mp3");
AudioAttributesaudio=newAudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(newInteger(128000));
audio.setChannels(newInteger(2));
audio.setSamplingRate(newInteger(44100));
EncodingAttributesattrs=newEncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoderencoder=newEncoder();
encoder.encode(source,target,attrs);

Jar下载地址:http://www.sauronsoftware.it/projects/jave/download.php

Ⅶ java读取wav 把wav放在哪儿

Applet有一个属性,类型为AppletStub。
你的Applet没有在页面中,AppletStub属性就会为null。

如果你想编写java的音频播放器,请使用jmf。
1、安装windows版jmf(当然,你的操作系统是windows)
2、把%安装目录%\lib\jmf.jar添加到classpath
注意:不能只是下载一个jmf.jar文件,然后添加到classpath,这是不行的。你需要安装jmf。

import java.io.File;
import java.io.IOException;

import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;

public class MyPlayer {
private static String path = "杀破狼.mp3";

public static void main(String[] args) {
File f1 = new File(path);
try {
Player player = Manager.createRealizedPlayer(f1.toURI().toURL());
player.prefetch();
player.start();
} catch (CannotRealizeException ex) {
} catch (NoPlayerException ex) {
} catch (IOException ex) {
}
}
}

Ⅷ 我用java转换的wav格式文件使用火狐浏览器无法播放

HTML5视频或音频的话,检查一下压缩码率,如果不是,浏览器需要安装相关插件才能播放,比如Flash,必须依赖插件才能正常播放,浏览器默认是不能直接打开的。

Ⅸ java如何播放wav文件

建议使用jmf(java media framwork),这样就能播放mp3等众多格式的音乐了;去sun官网下一个jmf,安装好后,把
jmf.jar包引入便可使用,给出例zi代码:使用方法:构造函数中传入文件路径名即可,播放、暂停、继续、停止等功能均已实现。

/*************************************************
* Subclass: MusicPlay
*************************************************/
public class MusicPlay implements Runnable {
private Time zeroTime = new Time(0);
private Player player;
private boolean isloop = false;

/*************************************************
* Function: MusicPlay Description: constructor, load the music file and
* get ready for play Called By: MultiMedia()
*************************************************/
// 实例化各个参数 filename 为文件名,可为绝对路径
public MusicPlay(String filename) {
File file = new File(filename);
try {
player = Manager.createRealizedPlayer(file.toURI().toURL());
player.addControllerListener(new ControllListener());
} catch (NoPlayerException e) {
e.printStackTrace();
} catch (CannotRealizeException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

/*************************************************
* Function: isRunning Description: test if this music is playing Called
* By:
*************************************************/
public boolean isRunning() {
return player.getState() == Player.Started;
}

/*************************************************
* Function: play Description: play the music for once Called By:
* resumeAll()
*************************************************/
// 只播放一次
public void play() {
if (!turnOff)
player.start();
}

/*************************************************
* Function: replay Description: replay the music Called By: musics that
* will be played many times will invoke this methed
*************************************************/
// 再播放一次
public void replay() {
if (turnOff)
return;

if (player.getState() == Controller.Prefetched)
player.setMediaTime(zeroTime);
player.start();
}

/*************************************************
* Function: stop Description: stop this music Called By: stopAll() of
* upper class,suspendAll() of upper
* class,BackroundForMenuPanel,GameOverPanel
*************************************************/
public void stop() {
player.stop();
}

/*************************************************
* Function: close Description: dispose the music Called By: closeAll()
* of super class
*************************************************/
public void close() {
player.stop();
player.close();
}

/*************************************************
* Function: loop Description: make the music played repetitiously
* Called By: music that will repetitious play
*************************************************/
// 循环播放
public void loop() {
if (turnOff)
return;

isloop = true;
player.prefetch();
replay();
}

/*************************************************
* Function: run Description: trig this music Called By: Override method
*************************************************/
@Override
public void run() {
loop();
}

/*************************************************
* Subclass: ControllListener Description: listener for playing and
* implement playing repetitiously
*************************************************/
// 通过对播放进度的监听,实现循环播放
private class ControllListener implements ControllerListener {

public void controllerUpdate(ControllerEvent e) {
if (e instanceof EndOfMediaEvent) {
if (isloop) {
player.setMediaTime(new Time(0));
player.start();
}
}
}
}

}

Ⅹ java如何对某文件夹内的wav文件批量改名

importjava.io.File;
publicclassChangeFileName{
publicstaticvoidchangeName(Stringpath){
intcount=1;
Filefile=newFile(path);
if(file.isDirectory()){
File[]dirFile=file.listFiles();
for(Filef:dirFile){
if(f.isDirectory())
continue;//changeName(f.getAbsolutePath());
else{
if(f.getName().endsWith(".wav")){
StringfileName="000"+count;
StringorigUrl=f.getAbsolutePath();
f.renameTo(newFile(origUrl.substring(0,origUrl.lastIndexOf('\')+1)+fileName.substring(fileName.length()-4)+".cvv"));
count+=1;
}
}
}
}
}
publicstaticvoidmain(String[]args){
StringfileUrl=System.getProperty("user.dir")+"/resource";
changeName(fileUrl);
}
}

阅读全文

与javawav文件相关的资料

热点内容
php备案号 浏览:986
php视频水印 浏览:163
怎么追程序员的女生 浏览:485
空调外压缩机电容 浏览:77
怎么将安卓变成win 浏览:457
手机文件管理在哪儿新建文件夹 浏览:723
加密ts视频怎么合并 浏览:775
php如何写app接口 浏览:803
宇宙的琴弦pdf 浏览:395
js项目提成计算器程序员 浏览:944
pdf光子 浏览:834
自拍软件文件夹名称大全 浏览:328
程序员留学移民 浏览:52
梁中间部位箍筋加密区 浏览:119
频谱分析pdf 浏览:752
乐2怎么升级安卓70 浏览:174
java中获取日期 浏览:508
单片机74hc245 浏览:274
美国历史上的总统pdf 浏览:753
程序员脱单实验室靠不靠谱 浏览:460