【问题标题】:Play Media in JSPX ADF?在 JSPX ADF 中播放媒体?
【发布时间】:2018-11-07 11:21:13
【问题描述】:

亲爱的,

我一直在尝试让 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"/>

filePath 看起来像这样:/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">

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

问候,

【问题讨论】:

    标签: java html plugins wav oracle-adf


    【解决方案1】:

    我已经设法通过使用音频 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>
    

    问候,

    【讨论】:

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