java 无法导入 javax.media.*; (包不存在)为什么这么说?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6875186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to import javax.media.*; (package does not exist) Why does it say so?
提问by program-o-steve
I have downloaded JMF MP3 PLUGIN to play mp3 files. After downloading i place mp3plugin.jar
into the project library of netbeans.
我已经下载了JMF MP3 PLUGIN来播放 mp3 文件。下载后我mp3plugin.jar
放入netbeans的项目库中。
Then i start the code with the line :
import javax.media.*;
然后我用以下行开始代码:
import javax.media.*;
But there is an error corresponding to this statement which says package javax.media
does not exist. Why do i get this error ? I have tried searching about it but haven't found the solution. Please help me in this.
I have also placed C:\Program Files\Java\jdk1.7.0\jre\lib\ext\mp3plugin.jar
in the classpath variable.
但是有一个与此语句相对应的错误,表示包javax.media
不存在。为什么我会收到这个错误?我试过搜索它,但没有找到解决方案。请帮助我。我还放置C:\Program Files\Java\jdk1.7.0\jre\lib\ext\mp3plugin.jar
在类路径变量中。
回答by Andrew Thompson
It is not necessary to import a Service Provider Interface at compile time. Simply add it to the run-time class-path and it will be able to play mp3's as well as its (default) wave/pcm/midi files.
没有必要在编译时导入服务提供者接口。只需将它添加到运行时类路径,它就可以播放 mp3 及其(默认)wave/pcm/midi 文件。
I use the [mp3plugin.jar][1]
this way for DukeBox, a little player for M3U style playlists, and it works just fine. Note that it will add the ability to read MP3 format using JavaSound (javax.sound.sampled
). If you intend playing the MP3 using the JMF player (which is unnecessary, and I do not recommend), you'll need to add the main JMF jar at both compile & run-time.
我[mp3plugin.jar][1]
对 DukeBox使用这种方式,这是一个用于 M3U 风格播放列表的小播放器,它工作得很好。请注意,它将添加使用 JavaSound ( javax.sound.sampled
)读取 MP3 格式的功能。如果您打算使用 JMF 播放器播放 MP3(这是不必要的,我不推荐),您需要在编译和运行时添加主 JMF jar。
Here is an example code for playing soundsusing JavaSound. Don't be put off by the length of the code, most of that is comments and explanation.
这是使用 JavaSound播放声音的示例代码。不要被代码的长度拖延,其中大部分是注释和解释。
It will compile without importing anyof JMF. If the mp3plugin.jar
is on the run-timeclass-path, it should be capable of playing MP3s.
它将在不导入任何JMF 的情况下进行编译。如果mp3plugin.jar
是在运行时类路径,它应该能够播放MP3音乐。
回答by rogerdpack
appears that it's not distributed by default with the JDK (at least 1.6 JDK). javax.sound.sampled is though I guess. Also see the other answer, but note that apparently using javax.sound for mp3's isn't always compatible with all mp3's see https://stackoverflow.com/a/7040010/32453
似乎默认情况下它没有随 JDK(至少 1.6 JDK)一起分发。javax.sound.sampled 是虽然我猜。另请参阅其他答案,但请注意,显然对 mp3 使用 javax.sound 并不总是与所有 mp3 兼容,请参阅 https://stackoverflow.com/a/7040010/32453