首页
学习
活动
专区
圈层
工具
发布

MP3问题
EN

Stack Overflow用户
提问于 2013-04-18 10:33:13
回答 1查看 5.4K关注 0票数 1

我使用Windows 7和可以"Java平台SE二进制“在我的声音混合器,但仍然没有声音似乎。

我的代码是:

代码语言:javascript
复制
import javax.media.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLExc;

public class SimpleAudioPlayer {
private Player audioPlayer = null;

public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException, 
    CannotRealizeException {
    audioPlayer = Manager.createRealizedPlayer(url);
}

public SimpleAudioPlayer(File file) throws IOException, NoPlayerException, 
    CannotRealizeException {
    this(file.toURL());
}

public void play() {
    audioPlayer.start();
}

public void stop() {
    audioPlayer.stop();
    audioPlayer.close();
}

public static void main(String[] args) {
    try{
        File audioFile = new File("/t.mp3");
        SimpleAudioPlayer player = new SimpleAudioPlayer(audioFile);

        System.out.println();
        System.out.println("-> Playing file '" + 
                           audioFile.getAbsolutePath() + "'");
        System.out.println("   Press the Enter key to exit");
        player.play();

        // wait for the user to press Enter to proceed.
        System.in.read();
        System.out.println("-> Exiting");
        player.stop();
    }catch(Exception ex){
        ex.printStackTrace();
    }

    System.exit(0);

}
}

我使用Windows Preformance JMF版本。试图播放的MP3 im在VLC/WMP中工作得很好,所以它不可能是文件。

代码在运行时也不会抛出任何异常或错误,只是它似乎没有播放声音。

我遗漏了什么吗?比如拉声卡?接管它,这样我就可以播放声音了?

我的总体目标是使用RTP/RTSP提供MP3流服务,所以任何链接、建议或tuturiols都会有帮助,因为我不使用IBM JMF TuturiolJava Demo

如果需要更多的信息,请询问!

更新-

下载的WAV文件和它似乎在播放,我如何使MP3s播放?

添加了格式并尝试了此代码,但仍然存在相同的问题:

代码语言:javascript
复制
import java.io.File;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;

public class SimpleAudioPlayer {
    public static void main(String[] args) {

        Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
        Format input2 = new AudioFormat(AudioFormat.MPEG);

        Format output = new AudioFormat(AudioFormat.LINEAR);
        PlugInManager.addPlugIn(
            "com.sun.media.codec.audio.mp3.JavaDecoder",
            new Format[]{input1, input2},
            new Format[]{output},
            PlugInManager.CODEC
        );
        try {
            Player player = Manager.createPlayer(new MediaLocator(new File("/t.mp3").toURI().toURL()));
            player.start();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

无法处理格式: mpeglayer3,44100.0 Hz,16位,立体声,LittleEndian,签名,16000.0帧速率,FrameSize=32768位无法实现: com.sun.media.PlaybackEngine@62deaa2e错误:无法实现com.sun.media.PlaybackEngine@62deaa2e

这就是错误!

EN

回答 1

Stack Overflow用户

发布于 2013-04-18 10:51:35

就像我想的,这是个丢失的编解码器。

我想这就是你需要的:http://www.oracle.com/technetwork/java/javase/download-137625.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16080606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档