Java Media Framework-MP3问题 [英] Java Media Framework - MP3 Issues

查看:128
本文介绍了Java Media Framework-MP3问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows 7,并且可以在混音器中使用"Java Platform SE Binary",但似乎仍然没有声音播放.

Im using Windows 7 and can "Java Platform SE Binary" in my sound mixer but yet still no sound seems to play.

我的代码是:

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在VLC/WMP中可以正常运行,因此不能成为文件.

I use the Windows Preformance JMF edition. The MP3 im trying to play works fine in VLC/WMP so it cant be the file.

代码在运行时也不会引发任何异常或错误,只是似乎没有播放声音.

The code also throws no exceptions or error when running, it just doesnt seem to play the sound.

有什么我想念的吗?喜欢拉声卡吗?例如.接管它,以便我可以播放声音了吗?

Is there something im missing? Like pulling the sound card? E.g. taking over it so i can play sound out of it?

我的总体目标是使用RTP/RTSP提供MP3流服务,因此使用

Im overall aim is to to a MP3 streaming service using RTP/RTSP so any links,advice or tuturiols would be help as im currelnt using IBM JMF Tuturiol and Java Demo

请询问是否需要更多信息!

Please ask if any more information is needed!

更新-

下载了 WAV文件,它似乎在播放,我该如何播放MP3?

Downloaded WAV FILE and it seemed to play, how can i make MP3s play?

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

Added formats and tried this code and still the same issue:

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

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

那是错误!

推荐答案

我认为这是缺少的编解码器.

As I thought, it's a missing codec.

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

I think this is what you need: http://www.oracle.com/technetwork/java/javase/download-137625.html

这篇关于Java Media Framework-MP3问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆