0
我有一個表格,我已經實現了Simple captcha每件事情都很好,但我希望當用戶點擊播放按鈕時播放音頻驗證碼。在我的情況下音頻播放默認在頁面加載。java中的簡單驗證碼音頻設置
下面是我的音頻驗證碼
public class MyAudioCaptcha extends AudioCaptchaServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
MyTextProducer myTextProducer = (MyTextProducer) req.getSession().getAttribute("myTextProducer");
if(myTextProducer == null){
myTextProducer = new MyTextProducer();
}
AudioCaptcha ac = new AudioCaptcha.Builder().
addAnswer(myTextProducer).
addNoise().
build(); // Required
CaptchaServletUtil.writeAudio(resp, ac.getChallenge());
req.getSession().setAttribute("audioCaptcha", ac);
} catch (Exception e) {
Util.AppendExceptionToLog(e);
}
}
}
JSP代碼代碼:
<script>
$(document).ready(function(){
reloadCaptcha();
});
function reloadCaptcha(){
var d = new Date();
$.ajax({
url:"captcha.jsp",
type :"POST",
async:true,
data: {
'action': 'generateCaptcha' ,
},
success:function(response){
$("#captcha_image").attr("src", "../../simpleCaptcha.png?"+d.getTime());
$("#captcha_audio").attr("src", "../../audio.wav?"+d.getTime());
},
});
}
</script>
<body>
<td>
<div class="inputfield" style="margin-left: 10px;">
<img id="captcha_image" />
<img src="../../images/reload.jpg" onclick="reloadCaptcha()" style="cursor: pointer;" alt="reload"width="30" height="30"/>
</div>
</td>
<td>
<audio controls autoplay id="captcha_audio" autoplay = "false"></audio>
</td>
</body>
有沒有在上面的代碼中的任何配置的,因此音頻不會在頁面加載播放,要播放的只有用戶點擊音頻captcha
您是否檢查過自動播放給定媒體的不是您的瀏覽器? [如何停止自動播放媒體](http://www.howtogeek.com/227669/how-to-stop-auto-playing-html5-videos-in-your-web-browser/) – Xephi
您可以添加您的視圖(JSP,HTML或其他)您的音頻驗證碼正在寫入? –
@TahirHussainMir我已添加jsp代碼 – pise