-->

Java媒体框架 - MP3的问题(Java Media Framework - MP3 Issu

2019-10-18 00:49发布

即时通讯使用的是Windows 7,并可以在“Java平台SE二进制”在我的调音台,但仍然没有声音似乎发挥。

我的代码是:

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性能与JMF版本。 该MP3即时试图发挥工作在VLC / WMP细所以它不能是文件。

该代码还没有抛出异常或错误运转时,它只是似乎没有播放声音。

是不是有什么我思念? 像拉声卡? 如接管它,这样我可以播放声音出来的吗?

林总的目标是要使用RTP / RTSP一个MP3流媒体服务,使任何链接,建议或tuturiols将有助于利用作为即时通讯currelnt IBM JMF Tuturiol和Java的演示

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

最新情况:

下载wav文件 ,它似乎玩,我怎么可以让MP3音乐播放?

新增的格式,并试图将此代码还是一样的问题:

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赫兹,16位,立体声,LittleEndian,签名,16000.0帧速率,框架尺寸= 32768个比特无法实现:com.sun.media.PlaybackEngine@62deaa2e错误:无法实现的com.sun。 media.PlaybackEngine@62deaa2e

那是错误!

Answer 1:

因为我认为,这是一个缺少编解码器。

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



文章来源: Java Media Framework - MP3 Issues
标签: java mp3 jmf