我使用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 Preformance JMF版本。试图播放的MP3 im在VLC/WMP中工作得很好,所以它不可能是文件。
代码在运行时也不会抛出任何异常或错误,只是它似乎没有播放声音。
我遗漏了什么吗?比如拉声卡?接管它,这样我就可以播放声音了?
我的总体目标是使用RTP/RTSP提供MP3流服务,所以任何链接、建议或tuturiols都会有帮助,因为我不使用IBM JMF Tuturiol和Java Demo。
如果需要更多的信息,请询问!
更新-
下载的WAV文件和它似乎在播放,我如何使MP3s播放?
添加了格式并尝试了此代码,但仍然存在相同的问题:
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
这就是错误!
发布于 2013-04-18 10:51:35
就像我想的,这是个丢失的编解码器。
我想这就是你需要的:http://www.oracle.com/technetwork/java/javase/download-137625.html
https://stackoverflow.com/questions/16080606
复制相似问题