java - 在 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">
所以我想知道是否有人以前尝试过
问候,
解决方案
我已经设法通过使用音频 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>
问候,
推荐阅读
- azure - 多租户 Azure 应用程序对其他租户不可见
- spring - Spring Boot 版本与 Vaadin 框架版本的兼容性
- web-services - SAP 中的 Web 服务是否默认可用?
- javascript - 重新排序不适用于新追加
- python - 我在抓取时产生数据,我需要在 orderde 字段中的 csv 文件中抓取数据
- android - 当我们在同一设备的单个应用程序中使用不同帐户时的 SQLite DB 问题
- linux - linux 中的 IE11 webdriver 是否支持硒测试?
- python - 使用数据框列值作为列名
- javascript - 在 echo 语句中连接 javascript 字符串和变量
- c# - 首次执行完成后,Topshelf 服务未自动运行