在Java中播放Windows Media音频文件(.wma) [英] play windows media audio file ( .wma ) in java

查看:256
本文介绍了在Java中播放Windows Media音频文件(.wma)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java中读取.wma歌曲文件.我正在使用此代码.但是此代码是错误的.

(错误== javax.sound.sampled.UnsupportedAudioFileException:无法从输入文件获取音频输入流)

how to read .wma song file in java. I''m using this code. but this code is error.

(Error == javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file )

private void playAudio() {
        try {
            File soundFile =
                    new File("Track_1.wma");
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
            audioFormat = audioInputStream.getFormat();
            System.out.println(audioFormat);

            DataLine.Info dataLineInfo =
                    new DataLine.Info(
                    SourceDataLine.class,
                    audioFormat);
            sourceDataLine =
                    (SourceDataLine) AudioSystem.getLine(
                    dataLineInfo);
            new PlayThread().start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

class PlayThread extends Thread {
        byte tempBuffer[] = new byte[10000];
        public void run() {
            try {
                sourceDataLine.open(audioFormat);
                sourceDataLine.start();
                int cnt;
                while ((cnt = audioInputStream.read(
                        tempBuffer, 0, tempBuffer.length)) != -1
                        && stopPlayback == false) {
                    if (cnt > 0) {
                        sourceDataLine.write(
                                tempBuffer, 0, cnt);
                    }
                }
                sourceDataLine.drain();
                sourceDataLine.close();
            } catch (Exception e) {
                e.printStackTrace();
            }




请帮帮我.
谢谢.




Please help me.
Thanks.

推荐答案

该异常将继续存在. * .wma文件不受标准支持.

在Java中,声音支持目前很差. Sound API并未积极开发,Oracle继Java开发之后就再也没有开发人员了.

最简单的解决方案是使用* .wav文件.

检查此内容以获得有关Sound API的一些信息:
Java声音程序员指南 [ Java MP3插件 [ http://fobs.sourceforge.net/ [ ^ ]
That exception will stay. *.wma files are not supported by standard.

The sound support is currently bad in Java. The Sound API is not developed actively, there is no developer left after oracle toke over the Java development.

Simplest solution would be to use *.wav files.

Check this for some information on the Sound API:
Java Sound Programmer Guide[^] @ oracle.com

There is a lib available for mp3 support under JMF:
Java MP3 PlugIn[^]

And the FOBS project is said to be supporting WMA-Files. But that Project is also not continuing:
http://fobs.sourceforge.net/[^]


这篇关于在Java中播放Windows Media音频文件(.wma)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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