/*! * Securimage CAPTCHA Audio Library * https://www.phpcaptcha.org/ * * Copyright 2015 phpcaptcha.org * Released under the BSD-3 license * See https://github.com/dapphp/securimage/blob/master/README.md */ var SecurimageAudio = function(options) { this.html5Support = true; this.flashFallback = false; this.captchaId = null; this.playing = false; this.reload = false; this.audioElement = null; this.controlsElement = null; this.playButton = null; this.playButtonImage = null; this.loadingImage = null; if (options.audioElement) { this.audioElement = document.getElementById(options.audioElement); } if (options.controlsElement) { this.controlsElement = document.getElementById(options.controlsElement); } this.init(); } SecurimageAudio.prototype.init = function() { var ua = navigator.userAgent.toLowerCase(); var ieVer = (ua.indexOf('msie') != -1) ? parseInt(ua.split('msie')[1]) : false; // ie 11+ detection if (!ieVer && null != (ieVer = ua.match(/trident\/.*rv:(\d+\.\d+)/))) ieVer = parseInt(ieVer[1]); var objAu = this.audioElement.getElementsByTagName('object'); if (objAu.length > 0) { objAu = objAu[0]; } else { objAu = null; } if (ieVer) { if (ieVer < 9) { // no html5 audio support, hide player controls this.controlsElement.style.display = 'none'; this.html5Support = false; return ; } else if ('' == this.audioElement.canPlayType('audio/wav')) { // check for mpeg tag - if not found then fallback to flash var sources = this.audioElement.getElementsByTagName('source'); var mp3support = false; var type; if (objAu) { this.flashFallback = true; } for (var i = 0; i < sources.length; ++i) { type = sources[i].attributes["type"].value; if (type.toLowerCase().indexOf('mpeg') >= 0 || type.toLowerCase().indexOf('mp3') >= 0) { mp3support = true; break; } } if (false == mp3support) { // browser supports