简体   繁体   English

如何在Netbeans Platform项目中使用ServiceLoader添加SPI

[英]How do I use ServiceLoader in a Netbeans Platform project to add SPIs

I'm trying to add MP3 capabilities to my Netbeans Platform project in Netbeans 8.0. 我正在尝试将MP3功能添加到Netbeans 8.0中的Netbeans Platform项目中。 I understand that this can be easily added to the javax.sound.sampled libraries using ServiceLoader and an SPI for the MP3 codecs. 我知道可以使用ServiceLoader和用于MP3编解码器的SPI轻松将其添加到javax.sound.sampled库中。

So I downloaded MP3 SPI and unzipped it, then in Netbeans I created a Jar wrapper module with the three jars that were in the zip file (one jar was in the root of the zip and two were under lib/ ). 因此,我下载了MP3 SPI并将其解压缩,然后在Netbeans中创建了一个Jar包装器模块,其中的三个jar位于zip文件中(一个jar位于zip的根目录中,而两个jar位于lib/ )。 Then I made the modules that need the MP3 functionality depend on this wrapper module. 然后,使需要MP3功能的模块依赖于此包装器模块。 But when I call AudioSystem.getAudioFileTypes() in those modules, "MP3" is not one of the types (only "WAVE", "AU" and "AIFF") 但是,当我在那些模块中调用AudioSystem.getAudioFileTypes()时,“ MP3”不是其中一种类型(只有“ WAVE”,“ AU”和“ AIFF”)

What am I missing? 我想念什么?

I checked that the correct files are listed under META-INF/services in the main jar. 我检查了主jar中META-INF/services下是否列出了正确的文件。

do I need to recreate the lib/ structure in my wrapper module? 我需要在包装模块中重新创建lib/结构吗? Does it make a difference what code-base I use for the wrapper module? 我为包装器模块使用的代码库是否有所不同? Do I need to alert the ServiceLoader somehow in my code? 我是否需要在代码中以某种方式提醒ServiceLoader?

Here is the project metadata for the wrapper module: 这是包装器模块的项目元数据:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
    <type>org.netbeans.modules.apisupport.project</type>
    <configuration>
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
            <code-name-base>org.sil.wrapper.mp3spi</code-name-base>
            <suite-component/>
            <module-dependencies/>
            <public-packages>
                <package>javazoom.jl.converter</package>
                <package>javazoom.jl.decoder</package>
                <package>javazoom.jl.player</package>
                <package>javazoom.jl.player.advanced</package>
                <package>javazoom.spi</package>
                <package>javazoom.spi.mpeg.sampled.convert</package>
                <package>javazoom.spi.mpeg.sampled.file</package>
                <package>javazoom.spi.mpeg.sampled.file.tag</package>
                <package>org.tritonus.share</package>
                <package>org.tritonus.share.midi</package>
                <package>org.tritonus.share.sampled</package>
                <package>org.tritonus.share.sampled.convert</package>
                <package>org.tritonus.share.sampled.file</package>
                <package>org.tritonus.share.sampled.mixer</package>
            </public-packages>
            <class-path-extension>
                <runtime-relative-path>ext/mp3spi1.9.5.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/mp3spi1.9.5.jar</binary-origin>
            </class-path-extension>
            <class-path-extension>
                <runtime-relative-path>ext/tritonus_share.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/tritonus_share.jar</binary-origin>
            </class-path-extension>
            <class-path-extension>
                <runtime-relative-path>ext/jl1.0.1.jar</runtime-relative-path>
                <binary-origin>release/modules/ext/jl1.0.1.jar</binary-origin>
            </class-path-extension>
        </data>
    </configuration>
</project>

It turns out that the SPI is working fine. 事实证明SPI工作正常。 It can read and play an MP3 file. 它可以读取和播放MP3文件。 However AudioSystem.getAudioFileTypes() lists file types that are writable, and the SPI doesn't provide the ability to write MP3 files. 但是AudioSystem.getAudioFileTypes()列出了可写的文件类型,并且SPI不提供写入MP3文件的功能。 It doesn't include a provider for javax.sound.sampled.spi.AudioFileWriter 它不包含javax.sound.sampled.spi.AudioFileWriter的提供程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM