Java媒体框架MP3问题
我使用Windows7,可以在我的混音器中使用“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 Performance JMF版本。我试图播放的MP3在VLC/WMP中运行良好,因此它不可能是文件
该代码在运行时也不会抛出异常或错误,只是似乎不会播放声音
我有什么遗漏吗?比如拔声卡?例如,接管它以便我可以播放它的声音
Im的总体目标是使用RTP/RTSP连接到MP3流媒体服务,因此,任何链接、建议或教程都将在Im当前使用IBM JMF Tuturiol和Java Demo时有所帮助
请询问是否需要更多信息
更新-
下载了WAV FILE并且它似乎在播放,我如何让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();
}
}
}
Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits Failed to realize: com.sun.media.PlaybackEngine@62deaa2e Error: Unable to realize com.sun.media.PlaybackEngine@62deaa2e
这就是错误
# 1 楼答案
正如我所想,这是一个丢失的编解码器
我想这就是你需要的:http://www.oracle.com/technetwork/java/javase/download-137625.html