且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法导入javax.media.*; (包不存在)为什么这样说?

更新时间:2023-10-10 22:27:52

在编译时不必导入服务提供者接口.只需将其添加到运行时类路径中,它将能够播放mp3以及其(默认)wave/pcm/midi文件.

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.

我将[mp3plugin.jar][1]这种方式用于DukeBox,这是M3U样式播放列表的小播放器,它工作得很好.请注意,它将添加使用JavaSound(javax.sound.sampled)读取MP3格式的功能.如果您打算使用JMF播放器播放MP3(这是不必要的,我不建议这样做),则需要在编译和添加两个主JMF jar的同时添加JMF jar.运行时.

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.

以下是使用JavaSound播放声音的示例代码.不要被代码的长度所困扰,其中大部分是注释和解释.

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.

它将编译而无需导入JMF的任何.如果mp3plugin.jar运行时类路径上,则它应该能够播放MP3.

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.