我从webService接收一个InputStream然后我将使用HTML5标签播放,所以为了播放音频,我需要将InputStream转换为URL,这样标签可以读取此流,因为它已经读取了的InputStream。
<!DOCTYPE html>
<%@page import="yourphone.voicemail.*"%>
<%@page import="com.verscom.ws.*"%>
<%@page import="com.verscom.methods.*"%>
<body>
<button onclick="playSound()">Play Me</button>
<button onclick="pausrSound()">Pause</button>
<audio id="audio" controls="controls">
<source id="mainSrc" type="audio/mp3" onplay="playSound()"></source>
</audio>
</body>
<script type="text/javascript">
var audio = document.getElementById("audio");
function playSound(){
<%
EndUserPortalWSServiceStub.GetVoiceMailMessageVcomResponse[] getvmMsgResp = new EndUserPortalWSServiceStub.GetVoiceMailMessageVcomResponse[2];
EndUserMethods endUserMethods = new EndUserMethods();
getvmMsgResp = endUserMethods.getVoiceMailList();
%>
audio.src= <%=getvmMsgResp[0].getVmailMessageWAVFile().getDataSource().getInputStream().toString()%>;
audio.play(); }
function pausrSound(){ audio.pause(); }
</script>