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

末鹿安然 提交于 2019-12-11 09:38:34

问题


I'm trying to add MP3 capabilities to my Netbeans Platform project in Netbeans 8.0. I understand that this can be easily added to the javax.sound.sampled libraries using ServiceLoader and an SPI for the MP3 codecs.

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/). Then I made the modules that need the MP3 functionality depend on this wrapper module. But when I call AudioSystem.getAudioFileTypes() in those modules, "MP3" is not one of the types (only "WAVE", "AU" and "AIFF")

What am I missing?

I checked that the correct files are listed under META-INF/services in the main jar.

do I need to recreate the lib/ structure in my wrapper module? 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?

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>

回答1:


It turns out that the SPI is working fine. It can read and play an MP3 file. However AudioSystem.getAudioFileTypes() lists file types that are writable, and the SPI doesn't provide the ability to write MP3 files. It doesn't include a provider for javax.sound.sampled.spi.AudioFileWriter



来源:https://stackoverflow.com/questions/27182184/how-do-i-use-serviceloader-in-a-netbeans-platform-project-to-add-spis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!