首页 > 解决方案 > 在 JSPX ADF 中播放媒体?

问题描述

亲爱的,

我一直在尝试让 ADF 页面播放存储在服务器上扩展名为“wav”的音频文件,但在使用时遇到了一个问题<af:media>

按照链接详细信息/说明:

https://docs.oracle.com/cd/E24001_01/apirefs.1111/e12419/tagdoc/af_media.html

到目前为止的结果,我设法使用托管 bean 获取路径我使用页面流范围将其作为源提供

<af:media source="#{pageFlowScope.filePath}" standbyText="Play Recording" id="m3"/>

文件路径看起来像这样:/recording/2018/11/07/test.wav

但是 Chrome 上的结果是这样的:

在此处输入图像描述

这是检查的元素:

<embed width="275" height="40" name="pt1:pc1:m3" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" autostart="0" src="/TestWebApp-ViewController-context-root/recording/2018/11/07/test.wav">

所以我想知道是否有人以前尝试过

问候,

标签: javahtmlpluginswavoracle-adf

解决方案


我已经设法通过使用音频 html5 解决了这个问题,并且托管 bean 使用 common-codec 库提供 base64 中的文件

 private String encodeFileToBase64Binary(String fileName)
                            throws IOException {

            File file = new File(convert(fileName));
            byte[] bytes = loadFile(file);
            byte[] encoded = Base64.encodeBase64(bytes);
            String encodedString = new String(encoded);

            return "data:audio/mpeg;base64,"+encodedString;
    }

    private static byte[] loadFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        long length = file.length();
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }
        byte[] bytes = new byte[(int)length];

        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }

        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }

        is.close();
        return bytes;
    }

我在给定路径的情况下调用了上述方法并将其存储在 pageFlowScope

jspx部分:

<audio src="${pageFlowScope.filePath}" controls="controls" controlsList="nodownload"></audio>

问候,


推荐阅读