包含javamp3格式的词条

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

本篇文章给大家谈谈javamp3格式,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

java如何实现播放mp3

简单的实例,代码如下,纯粹JMF加载MP3并播放:

import javax.media.*;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

public class PlayerMusic implements ControllerListener {// ControllerListener

// 控制事件

private Player player;

private boolean first, loop;

private String path;

private List mp3List;

private int mp3NO = 0;

PlayerMusic(List mp3List) {

this.mp3List = mp3List;

}

public void start() {

try {

player = Manager.createPlayer(new MediaLocator("file://" + mp3List.get(mp3NO)));

} catch (NoPlayerException ex) {

ex.printStackTrace();

System.out.println("不能播放文件");

return;

} catch (IOException ex) {

ex.printStackTrace();

return;

}

if (player == null) {

System.out.println("播放器为空");

return;

}

first = false;

player.addControllerListener(this);

// 提取媒体内容

player.prefetch();

}

public void controllerUpdate(ControllerEvent e) {

// 当媒体播放结束时,循环播放

if (e instanceof EndOfMediaEvent) {

mp3NO++;

if(mp3NOthis.mp3List.size()){

this.start();

}

return;

}

// 当预提取媒体的内容结束

if (e instanceof PrefetchCompleteEvent) {

player.start();

return;

}

// 当实例化后

if (e instanceof RealizeCompleteEvent) {

// pack(); //执行pack()操作

return;

}

}

public static void main(String[] args) {

List mp3List = new ArrayList();

mp3List.add("d://a.mp3");

mp3List.add("d://b.mp3");

mp3List.add("d://c.mp3");

PlayerMusic pm = new PlayerMusic(mp3List);

pm.start();

}

}

Java如何只输出 MP3格式的文件?

//汗,管理员。这真的是我自己在Eclipse上写好,然后一键复制上来的,不是拷贝别人的。JAVA代码都长这样好吗....

import java.io.File;

import java.io.IOException;

public class text {

//枚举一个文件夹下的所有MP3文件(不包括子目录)

public static void main(String[] args) {

System.out.println("请输入一个目录名");

byte[] input = new byte[50];

try {

System.in.read(input);

String path = new String(input).trim();

System.out.println("输入的目录为:" + path);

File file = new File(path);

if (file.exists()  file.isDirectory()) {

File[] files = file.listFiles();

if (files != null  files.length  0) {

for (File fileTemp : files) {

if (fileTemp.isFile()) {

String dir = fileTemp.getAbsolutePath();

if (dir.endsWith(".mp3") || dir.endsWith(".MP3")) {

System.out.println(dir);

}

}

  }

}else {

System.out.println("该文件夹下没有MP3文件!");

}

}else {

System.out.println("错误:这不是一个有效的文件夹");

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

献丑了,不喜勿喷!

java实现 mp3格式转换wav

/*

* 实现录音机的功能

*/

package com.liuyun.MyRecord1;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.io.*;

import javax.sound.sampled.*;

import java.lang.*;

public class MyRecord extends JFrame implements ActionListener{

//定义录音格式

AudioFormat af = null;

//定义目标数据行,可以从中读取音频数据,该 TargetDataLine 接口提供从目标数据行的缓冲区读取所捕获数据的方法。

TargetDataLine td = null;

//定义源数据行,源数据行是可以写入数据的数据行。它充当其混频器的源。应用程序将音频字节写入源数据行,这样可处理字节缓冲并将它们传递给混频器。

SourceDataLine sd = null;

//定义字节数组输入输出流

ByteArrayInputStream bais = null;

ByteArrayOutputStream baos = null;

//定义音频输入流

AudioInputStream ais = null;

//定义停止录音的标志,来控制录音线程的运行

Boolean stopflag = false;

//记录开始录音的时间

long startPlay;

//定义所需要的组件

JPanel jp1,jp2,jp3;

JLabel jl1=null;

JButton captureBtn,stopBtn,playBtn,saveBtn;

public static void main(String[] args) {

//创造一个实例

MyRecord mr = new MyRecord();

}

//构造函数

public MyRecord()

{

//组件初始化

jp1 = new JPanel();

jp2 = new JPanel();

jp3 = new JPanel();

//定义字体

Font myFont = new Font("华文新魏",Font.BOLD,30);

jl1 = new JLabel("录音机功能的实现");

jl1.setFont(myFont);

jp1.add(jl1);

captureBtn = new JButton("开始录音");

//对开始录音按钮进行注册监听

captureBtn.addActionListener(this);

captureBtn.setActionCommand("captureBtn");

//对停止录音进行注册监听

stopBtn = new JButton("停止录音");

stopBtn.addActionListener(this);

stopBtn.setActionCommand("stopBtn");

//对播放录音进行注册监听

playBtn = new JButton("播放录音");

playBtn.addActionListener(this);

playBtn.setActionCommand("playBtn");

//对保存录音进行注册监听

saveBtn = new JButton("保存录音");

saveBtn.addActionListener(this);

saveBtn.setActionCommand("saveBtn");

this.add(jp1,BorderLayout.NORTH);

this.add(jp2,BorderLayout.CENTER);

this.add(jp3,BorderLayout.SOUTH);

jp3.setLayout(null);

jp3.setLayout(new GridLayout(1, 4,10,10));

jp3.add(captureBtn);

jp3.add(stopBtn);

jp3.add(playBtn);

jp3.add(saveBtn);

//设置按钮的属性

captureBtn.setEnabled(true);

stopBtn.setEnabled(false);

playBtn.setEnabled(false);

saveBtn.setEnabled(false);

//设置窗口的属性

this.setSize(400,300);

this.setTitle("录音机");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocationRelativeTo(null);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("captureBtn"))

{

//点击开始录音按钮后的动作

//停止按钮可以启动

captureBtn.setEnabled(false);

stopBtn.setEnabled(true);

playBtn.setEnabled(false);

saveBtn.setEnabled(false);

//调用录音的方法

capture();

//记录开始录音的时间

startPlay = System.currentTimeMillis();

}else if (e.getActionCommand().equals("stopBtn")) {

//点击停止录音按钮的动作

captureBtn.setEnabled(true);

stopBtn.setEnabled(false);

playBtn.setEnabled(true);

saveBtn.setEnabled(true);

//调用停止录音的方法

stop();

//记录停止录音的时间

long stopPlay = System.currentTimeMillis();

//输出录音的时间

System.out.println("Play continues " + (stopPlay-startPlay));

}else if(e.getActionCommand().equals("playBtn"))

{

//调用播放录音的方法

play();

}else if(e.getActionCommand().equals("saveBtn"))

{

//调用保存录音的方法

save();

}

}

//开始录音

public void capture()

{

try {

//af为AudioFormat也就是音频格式

af = getAudioFormat();

DataLine.Info info = new DataLine.Info(TargetDataLine.class,af);

td = (TargetDataLine)(AudioSystem.getLine(info));

//打开具有指定格式的行,这样可使行获得所有所需的系统资源并变得可操作。

td.open(af);

//允许某一数据行执行数据 I/O

td.start();

//创建播放录音的线程

Record record = new Record();

Thread t1 = new Thread(record);

t1.start();

} catch (LineUnavailableException ex) {

ex.printStackTrace();

return;

}

}

//停止录音

public void stop()

{

stopflag = true;

}

//播放录音

public void play()

{

//将baos中的数据转换为字节数据

byte audioData[] = baos.toByteArray();

//转换为输入流

bais = new ByteArrayInputStream(audioData);

af = getAudioFormat();

ais = new AudioInputStream(bais, af, audioData.length/af.getFrameSize());

try {

DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, af);

sd = (SourceDataLine) AudioSystem.getLine(dataLineInfo);

sd.open(af);

sd.start();

//创建播放进程

Play py = new Play();

Thread t2 = new Thread(py);

t2.start();

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

//关闭流

if(ais != null)

{

ais.close();

}

if(bais != null)

{

bais.close();

}

if(baos != null)

{

baos.close();

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

//保存录音

public void save()

{

//取得录音输入流

af = getAudioFormat();

byte audioData[] = baos.toByteArray();

bais = new ByteArrayInputStream(audioData);

ais = new AudioInputStream(bais,af, audioData.length / af.getFrameSize());

//定义最终保存的文件名

File file = null;

//写入文件

try {

//以当前的时间命名录音的名字

//将录音的文件存放到F盘下语音文件夹下

File filePath = new File("F:/语音文件");

if(!filePath.exists())

{//如果文件不存在,则创建该目录

filePath.mkdir();

}

long time = System.currentTimeMillis();

file = new File(filePath+"/"+time+".wav");

AudioSystem.write(ais, AudioFileFormat.Type.WAVE, file);

//将录音产生的wav文件转换为容量较小的mp3格式

//定义产生后文件名

String tarFileName = time+".mp3";

Runtime run = null;

try {

run = Runtime.getRuntime();

long start=System.currentTimeMillis();

//调用解码器来将wav文件转换为mp3文件

strongspan style="color:#ff0000;"Process p=run.exec(filePath+"/"+"lame -b 16 "+filePath+"/"+file.getName()+" "+filePath+"/"+tarFileName); //16为码率,可自行修改

/span/strong//释放进程

p.getOutputStream().close();

p.getInputStream().close();

p.getErrorStream().close();

p.waitFor();

long end=System.currentTimeMillis();

System.out.println("convert need costs:"+(end-start)+"ms");

//删除无用的wav文件

if(file.exists())

{

file.delete();

}

} catch (Exception e) {

e.printStackTrace();

}finally{

//最后都要执行的语句

//run调用lame解码器最后释放内存

run.freeMemory();

}

} catch (Exception e) {

e.printStackTrace();

}finally{

//关闭流

try {

if(bais != null)

{

bais.close();

}

if(ais != null)

{

ais.close();

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

//设置AudioFormat的参数

public AudioFormat getAudioFormat()

{

//下面注释部分是另外一种音频格式,两者都可以

AudioFormat.Encoding encoding = AudioFormat.Encoding.

PCM_SIGNED ;

float rate = 8000f;

int sampleSize = 16;

String signedString = "signed";

boolean bigEndian = true;

int channels = 1;

return new AudioFormat(encoding, rate, sampleSize, channels,

(sampleSize / 8) * channels, rate, bigEndian);

//      //采样率是每秒播放和录制的样本数

//      float sampleRate = 16000.0F;

//      // 采样率8000,11025,16000,22050,44100

//      //sampleSizeInBits表示每个具有此格式的声音样本中的位数

//      int sampleSizeInBits = 16;

//      // 8,16

//      int channels = 1;

//      // 单声道为1,立体声为2

//      boolean signed = true;

//      // true,false

//      boolean bigEndian = true;

//      // true,false

//      return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,bigEndian);

}

//录音类,因为要用到MyRecord类中的变量,所以将其做成内部类

class Record implements Runnable

{

//定义存放录音的字节数组,作为缓冲区

byte bts[] = new byte[10000];

//将字节数组包装到流里,最终存入到baos中

//重写run函数

public void run() {

baos = new ByteArrayOutputStream();

try {

stopflag = false;

while(stopflag != true)

{

//当停止录音没按下时,该线程一直执行

//从数据行的输入缓冲区读取音频数据。

//要读取bts.length长度的字节,cnt 是实际读取的字节数

int cnt = td.read(bts, 0, bts.length);

if(cnt  0)

{

baos.write(bts, 0, cnt);

}

}

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

//关闭打开的字节数组流

if(baos != null)

{

baos.close();

}

} catch (IOException e) {

e.printStackTrace();

}finally{

td.drain();

td.close();

}

}

}

}

//播放类,同样也做成内部类

class Play implements Runnable

{

//播放baos中的数据即可

public void run() {

byte bts[] = new byte[10000];

try {

int cnt;

//读取数据到缓存数据

while ((cnt = ais.read(bts, 0, bts.length)) != -1)

{

if (cnt  0)

{

//写入缓存数据

//将音频数据写入到混频器

sd.write(bts, 0, cnt);

}

}

} catch (Exception e) {

e.printStackTrace();

}finally{

sd.drain();

sd.close();

}

}

}

}

怎么使用java将amr格式的文件转换成mp3格式的

步骤

运行添加视频文件。打开狸(liwo)窝全能转换器后,单击界面左上角的第一个按钮“添加视频”,浏览打开文件夹并将amr音乐文件导入到软件。有的用户可以会疏忽的,就是在打开文件夹时没发现有amr文件,其实有可能忘掉选择文件类型了,选择All Files(*.*),即所有文件,就可以看到了。

视频编辑。软件提供有视频编辑和3D效果的功能,这是对视频而言的。对于音频,我们可以使用软件的视频编辑功能。单击主界面左上方第二个按钮“视频编辑”,即可进入编辑窗口。如图所示,可以对音频进行切割,比如音乐太大的时候可以用,剪掉不需要的一段,保存需要的一段。

选择预置方案。软件支持输出aac、ac3、aiff、amr、m4a、mp2、mp3、ogg、ra、au、wav、wma、mka、flac(无损)、wav(无损)等格式音频。这里在分类“常用音频”中就可以找到需要转换的mp3格式-MP3-MPEG Layer-3 Audio (*.mp3) 流行的音频格式,具有很好的音质和很小的体积。

参数设置。在“预置方案”右边是“高级设置”,单击进入设置窗口,可以进行音频参数设置。新手不用进行此项设置,因为软件已经按照常用格式,使用范围等进行分类设置了,其参数相差不大。只是按照所需要的在预置方案中选择相应格式即可。

5

开始转换。设置完毕后,单击主界面右下角的圆形按钮,软件开始转换音频文件。转换没有先后顺序,是同时进行转换。软件转换速度较快,加上音频文件体积本来就不大,最多的一分钟即可转换完毕

javamp3格式的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javamp3格式的信息别忘了在本站进行查找喔。

发布于 2023-03-06 05:03:37
收藏
分享
海报
53
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了