{"name":"QR Text Reader","key":"qrtextreader","version":"1.0.1","instructions":"Reads text encoded in QR codes aloud\n","showatto":"1","showplayers":"0","requirecss":"","requirejs":"/filter/poodll/amd/src/poodll_qrscanner.js","shim":"","defaults":"width=320,height=240","amd":"1","body":"<div style=\"width: @@width@@px\"><button type=\"button\" id=\"@@AUTOID@@_button\" style=\"margin: auto;\"><i class=\"fa fa-qrcode\"></i></button>\n</div>\n<video id=\"@@AUTOID@@\" width=\"@@width@@px\" height=\"@@height@@px\" class=\"hide\" playsinline></video>\n<audio id=\"@@AUTOID@@_player\" src=\"\"></audio>\n</div>","bodyend":"","script":"var qrs= requiredjs_qrtextreader;\nvar poodllfilelib = M.cfg.wwwroot + '/filter/poodll/poodllfilelib.php?datatype=speaktext&paramone=';\nvar thecam=$('#' + @@AUTOID@@);\nvar thebutton=$('#' + @@AUTOID@@ + '_button');\nvar theplayer=$('#' + @@AUTOID@@ + '_player');\n\n//This flag is so we dont scan while playing\nvar suspendScan=false;\n\n//when the player stops we recommence scan\n$(theplayer).bind('ended',function(){suspendScan=false; qrs.startScan('' + @@AUTOID@@);});\n\n\nthebutton.click(function(){\n   theplayer[0].setAttribute('src',M.cfg.wwwroot + '/filter/poodll/ding.mp3');\n\n//we play a ding to warm up the touch device audio player\n   var pp = theplayer[0].play();\nif (pp !== undefined) {\n  pp.then(function() {\n    console.log('playing');\n  }).catch(function(error) {\n     //do nothing . This is just so we trigger something for touch devices\n  });\n}\n\n//we start the webcam\n  qrs.startWebCam('' + @@AUTOID@@);\n\n//we tell what to do when a scan happened\n  qrs.setCallback(function(data){\n     \n    //The logic here: https://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript\n    // bytes->utf8 = unescape(encodeURIComponent(data));\n    // utf-8->bytes = decodeURIComponent(escape(data))\n    //we encode utf8 for qrcode writing but after reading we we need encode right away to send as url\n    //so we simply escape the data read from qrcode. make sense? \n     //console.log(decodeURIComponent(escape(data)));\n     var src = poodllfilelib+ escape(data);\n\n     //we do not continue if we are already processing a previous scan\n     if(suspendScan){return;}\n\n   //we set data to player and play\n     theplayer.attr('src',src);\n     var pp = theplayer[0].play();\n     suspendScan=true;\n     if (pp !== undefined) {\n        pp.then(function() {\n        console.log('playing');\n      }).catch(function(error) {\n         console.log(error);\n         suspendScan=false;\n      });\n   }//end of if PP\n\n     //TO DO: I think we could delete this line\n     qrs.startScan('' + @@AUTOID@@);\n\n});//end of callback\n\n  qrs.startScan('' + @@AUTOID@@);\n  thecam.show();\n}); //end of button click\n\n ","style":"","dataset":"","datasetvars":"","alternate":"","alternateend":""}