java中播放音乐的问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 16:11:06
我在JAVA中用swing做一个小项目,要播放音乐,我从别地方拷来一个
.mid的播放文件就能用起来,为什么我把自己机子上面的mp3文件后缀名改成.mid执行后就会报
java.io.IOException: could not create audio stream from input stream

程序的代码是这样的,程序不会有错,可能是文件转换有什么问题,高手指点下
package test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import sun.audio.*;
import java.io.*;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;

public class testsong extends JFrame implements ActionListener{
AudioStream as;
FileInputStream fileau;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
// AudioPlayer.player.stop(as);
testsong(){
try {
jbInit();
} catch (Exception ex)

我晕死你,java默认只能播放mid wave格式,你把mp3改名,java读取的时候是按字节流读取,改了名其实文件本质还是mp3,他读不到mid的流当然报错了。

java.io.IOException: could not create audio stream from input stream

这就是 无法从字节流创建相应的音频媒体流的意思