Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-尝试使用mp3plugin播放mp3文件时出错_Java_Plugins_Jar_Mp3_Javax.sound.sampled - Fatal编程技术网

Java-尝试使用mp3plugin播放mp3文件时出错

Java-尝试使用mp3plugin播放mp3文件时出错,java,plugins,jar,mp3,javax.sound.sampled,Java,Plugins,Jar,Mp3,Javax.sound.sampled,我正在编写一个音乐可视化程序,并尝试使用mp3plugin()在java中播放mp3文件。然而,我遇到了一个错误,可能是因为我缺乏使用这个插件和编写音乐的经验 我已经用大量的mp3文件测试了这段代码,所有的问题都是一样的,我相信我可以有信心地排除mp3文件的错误 我的代码如下: AudioInputStream audioIn; try { JS_MP3FileReader m = new JS_MP3FileReader(); audioIn = m.getAudioInput

我正在编写一个音乐可视化程序,并尝试使用mp3plugin()在java中播放mp3文件。然而,我遇到了一个错误,可能是因为我缺乏使用这个插件和编写音乐的经验

我已经用大量的mp3文件测试了这段代码,所有的问题都是一样的,我相信我可以有信心地排除mp3文件的错误

我的代码如下:

AudioInputStream audioIn;
try {
    JS_MP3FileReader m = new JS_MP3FileReader();
    audioIn = m.getAudioInputStream(new File(ex.trackname));
    //audioIn = AudioSystem.getAudioInputStream(new File(ex.trackname));
    // Get a sound clip resource.
    Clip clip = AudioSystem.getClip();
    // Open audio clip and load samples from the audio input stream.
    clip.open(audioIn);
    clip.start();
} catch (Exception e) {
    e.printStackTrace();
}
我得到的错误是:

javax.sound.sampled.LineUnavailableException: line with format MPEG1L3 48000.0 Hz, unknown bits per sample, stereo, unknown frame size, unknown frame rate,  not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
at Logic.Run$1.run(Run.java:101)
at java.lang.Thread.run(Unknown Source)
(请注意,我编写的运行此代码的类实例称为Run)

我的项目结构如下,包括插件文件:


我直接使用JavaSound来播放mp3音频,效果非常好

以下是完整的工作代码(祝您玩得开心):

包XXXXXXXXXXXXX
导入java.io.File;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.Map;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javax.sound.sampled.*;
公共级音频播放器
{
private int bufferSize=4096;//Tamanho de buffer padrÃo 4k
private=false;
私有最终对象锁=新对象();
专用数据线;
私有int secondsFade=0;
私人ArrayList

tritonus\u share.jar

发现于

AudioUtil.java

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
public class AudioUtil
{
    private static ArrayList<FileMap> cache = new ArrayList<FileMap>();
    private static int _CACHE_SIZE = 5;

    public static Map<String, Object> getMetadata(File filename) throws Exception
    {
        FileMap fm = new FileMap(filename, null);
        int index = cache.indexOf(fm);
        if(index >= 0)
            return cache.get(index).getMap();

        AudioFileFormat format = AudioSystem.getAudioFileFormat(filename);

        Map<String, Object> mapa = new HashMap<String, Object>();
        mapa.putAll(format.properties());


        if(mapa.get("author") == null && filename.getName().contains(" - "))
        {
            mapa = new HashMap<String, Object>();
            String[] s = filename.getName().split(" - ");
            mapa.put("author", s[0]);
            s[1] = s[1].substring(0, s[1].length()-4);
            mapa.put("title", s[1]);
        }

        if(mapa.get("author") == null)
        {
            mapa.put("author", "Desconhecido");
            mapa.put("title", "Desconhecido");
        }

        Object o = format.properties().get("duration");

        if(o == null)
            mapa.put("duration", 0);

        fm.setMap(mapa);
        cache.add(fm);
        while(cache.size() > _CACHE_SIZE)
            cache.remove((int)0);

        return mapa;
    }
}

class FileMap
{
    private File file;
    private Map<String, Object> map;

    public FileMap(File file, Map<String, Object> map) 
    {
        this.file = file;
        this.map = map;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    @Override
    public boolean equals(Object obj) 
    {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FileMap other = (FileMap) obj;
        if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) 
        {
            return false;
        }
        return true;
    }

}
导入java.io.File;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.Map;
导入javax.sound.sampled.AudioFileFormat;
导入javax.sound.sampled.AudioSystem;
公共类AudioUtil
{
私有静态ArrayList缓存=新建ArrayList();
私有静态int_CACHE_SIZE=5;
公共静态映射getMetadata(文件名)引发异常
{
FileMap fm=新的FileMap(文件名,null);
int index=cache.indexOf(fm);
如果(索引>=0)
返回cache.get(index.getMap();
AudioFileFormat=AudioSystem.getAudioFileFormat(文件名);
Map mapa=新的HashMap();
mapa.putAll(format.properties());
if(mapa.get(“author”)==null&&filename.getName()包含(“-”)
{
mapa=新的HashMap();
字符串[]s=filename.getName().split(“-”);
mapa.put(“作者”,s[0]);
s[1]=s[1]。子字符串(0,s[1]。长度()-4);
mapa.put(“标题”,s[1]);
}
if(mapa.get(“author”)==null)
{
mapa.put(“作者”、“描述人”);
mapa.put(“标题”、“描述”);
}
对象o=format.properties().get(“持续时间”);
如果(o==null)
mapa.put(“持续时间”,0);
fm.setMap(mapa);
cache.add(fm);
while(cache.size()>\u cache\u size)
cache.remove((int)0);
返回mapa;
}
}
类文件映射
{
私有文件;
私人地图;
公共文件映射(文件文件,映射映射)
{
this.file=文件;
this.map=map;
}
公共文件getFile(){
返回文件;
}
公共无效设置文件(文件){
this.file=文件;
}
公共地图getMap(){
返回图;
}
公共无效集合映射(映射映射){
this.map=map;
}
@凌驾
公共布尔等于(对象obj)
{
if(obj==null){
返回false;
}
如果(getClass()!=obj.getClass()){
返回false;
}
最终文件映射其他=(文件映射)对象;
如果(this.file!=other.file&(this.file==null | | |!this.file.equals(other.file)))
{
返回false;
}
返回true;
}
}

格式为MPEG1L3 48000.0 Hz的行,每个采样未知位,立体声,未知帧大小,未知帧速率,不受支持
我几乎可以肯定我指示您的不会以这种方式报告。请重试。我怀疑该信息来自编码不正确的VBR MP3。我已再次尝试,同样的问题。使用完全相同的输出?!?48000.0赫兹的频率发生了变化,但除此之外,输出是相同的。在哪里可以找到AudioPlayerListener??
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
public class AudioUtil
{
    private static ArrayList<FileMap> cache = new ArrayList<FileMap>();
    private static int _CACHE_SIZE = 5;

    public static Map<String, Object> getMetadata(File filename) throws Exception
    {
        FileMap fm = new FileMap(filename, null);
        int index = cache.indexOf(fm);
        if(index >= 0)
            return cache.get(index).getMap();

        AudioFileFormat format = AudioSystem.getAudioFileFormat(filename);

        Map<String, Object> mapa = new HashMap<String, Object>();
        mapa.putAll(format.properties());


        if(mapa.get("author") == null && filename.getName().contains(" - "))
        {
            mapa = new HashMap<String, Object>();
            String[] s = filename.getName().split(" - ");
            mapa.put("author", s[0]);
            s[1] = s[1].substring(0, s[1].length()-4);
            mapa.put("title", s[1]);
        }

        if(mapa.get("author") == null)
        {
            mapa.put("author", "Desconhecido");
            mapa.put("title", "Desconhecido");
        }

        Object o = format.properties().get("duration");

        if(o == null)
            mapa.put("duration", 0);

        fm.setMap(mapa);
        cache.add(fm);
        while(cache.size() > _CACHE_SIZE)
            cache.remove((int)0);

        return mapa;
    }
}

class FileMap
{
    private File file;
    private Map<String, Object> map;

    public FileMap(File file, Map<String, Object> map) 
    {
        this.file = file;
        this.map = map;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    @Override
    public boolean equals(Object obj) 
    {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FileMap other = (FileMap) obj;
        if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) 
        {
            return false;
        }
        return true;
    }

}