【问题标题】:How do I use ServiceLoader in a Netbeans Platform project to add SPIs如何在 Netbeans 平台项目中使用 ServiceLoader 添加 SPI
【发布时间】:2014-11-28 05:00:21
【问题描述】:

我正在尝试在 Netbeans 8.0 中将 MP3 功能添加到我的 Netbeans 平台项目中。我知道这可以使用 ServiceLoader 和 MP3 编解码器的 SPI 轻松添加到 javax.sound.sampled 库中。

所以我下载了MP3 SPI 并将其解压缩,然后在Netbeans 中创建了一个Jar 包装模块,其中包含zip 文件中的三个jar(一个jar 在zip 的根目录中,两个在lib/ 下) .然后我使需要 MP3 功能的模块依赖于这个包装模块。但是当我在这些模块中调用AudioSystem.getAudioFileTypes() 时,“MP3”不是其中一种类型(只有“WAVE”、“AU”和“AIFF”)

我错过了什么?

我检查了主 jar 中的 META-INF/services 下是否列出了正确的文件。

我需要在我的包装模块中重新创建lib/ 结构吗?我为包装器模块使用的代码库有什么不同吗?我是否需要在我的代码中以某种方式提醒 ServiceLoader?

这是包装模块的项目元数据:

<?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>

【问题讨论】:

  • 也许我还应该提到我正在使用 Ubuntu,如果这有影响的话,虽然我希望最终的可分发是跨平台的。

标签: java netbeans wrapper netbeans-platform netbeans-8


【解决方案1】:

事实证明 SPI 工作正常。它可以读取和播放 MP3 文件。但是AudioSystem.getAudioFileTypes() 列出了可写的文件类型,并且 SPI 不提供写入 MP3 文件的能力。它不包括javax.sound.sampled.spi.AudioFileWriter 的提供者

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    相关资源
    最近更新 更多