在 JSPX ADF 中播放媒体?
Play Media in JSPX ADF?
亲爱的,
我一直在尝试让 ADF 页面播放存储在服务器上的扩展名为 "wav" 的音频文件,我遇到了一个问题,当我使用 <af:media>
在 link details/Instructions 之后:
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 使用通用编解码器库
以 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>
此致,
亲爱的,
我一直在尝试让 ADF 页面播放存储在服务器上的扩展名为 "wav" 的音频文件,我遇到了一个问题,当我使用 <af:media>
在 link details/Instructions 之后:
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 使用通用编解码器库
以 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>
此致,