开发者

unable to import javax.media.*; (package does not exist) Why does it say so?

开发者 https://www.devze.com 2023-03-24 00:54 出处:网络
I have downloaded JMF MP3 PLUGINto play mp3 files. After downloading i place mp3plugin.jar into the project library of netbeans.

I have downloaded JMF MP3 PLUGIN to play mp3 files. After downloading i place mp3plugin.jar into the project library of netbeans.

Then i start the code with the line : import javax.media.*;

But there is an error corresponding to this statement which says p开发者_StackOverflowackage 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.


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.

I use the mp3plugin.jar 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.


Here is an example code for playing sounds using JavaSound. Don't be put off by the length of the code, most of that is comments and explanation.

It will compile without importing any of JMF. If the mp3plugin.jar is on the run-time class-path, it should be capable of playing MP3s.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号