Logic Machine Forum
.play() and Chrome ! - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: .play() and Chrome ! (/showthread.php?tid=884)



.play() and Chrome ! - JMM - 04.07.2017

Hi,

This script works perfectly with IE and Firefox but not with Chrome (Win. and Android).

Someone would have an idea for this problem ?


Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" version="1.1" baseProfile="full" viewBox="0 0 0 0" id="root">
 
 <defs>
   <script type="text/javascript">
   <![CDATA[
    var p = window.parent, root, addr;
    var ip = location.host;
    var audio0 = "http://192.168.1.10/scada/resources/img/";
         root = document.getElementById('root');
            if (p && p.objectStore) {
                addr = p.Scada.encodeGroupAddress('0/0/202');
                p.objectStore.addListener(addr, function (obj) {
                    
                    if (obj.value !== 0) {
                        var snd0 = new Audio("" + audio0 + obj.value + "_on.mp3");
                        snd0.play();
                    }
                                        
                });
            }

   ]]>
   </script>
 </defs>
</svg>

Regards,
JMM.


RE: .play() and Chrome ! - buuuudzik - 04.07.2017

Please check what kind od error is in the console.


RE: .play() and Chrome ! - JMM - 04.07.2017

Thanks for the help

No error in the console. Sad


RE: .play() and Chrome ! - admin - 04.07.2017

Chrome requires some kind of user interaction before audio can be played. See this post for a work-around:
https://forum.logicmachine.net/showthread.php?tid=275&pid=2449#pid2449

If you need a simple "beep" sound, you can try this example:
https://forum.logicmachine.net/showthread.php?tid=275&pid=1616#pid1616


RE: .play() and Chrome ! - JMM - 04.07.2017

.play(), works very well in a simple page HTM with Chrome, but once integrated into LM do not work any more.

With IE or Firefox is OK !.

JMM.

Thanks Admin !

I need to read alerts in MP3 and;
https://forum.logicmachine.net/showthread.php?tid=275&pid=2449#pid2449
is for IOS not Android or Win.
Sad


RE: .play() and Chrome ! - JMM - 04.07.2017

HI,

with this script added into the custom javascript, it is OK for:

-Firefox and Chrome (windows)
-Firefox (Android)

And always bad for Chrome (Android) !!
an idea? Sad

Code:
//-------ALARME MP3--------------------------------------  
 
 
      var p = window.parent, root, addr;
     var audio0 = "http://192.168.1.10/scada/resources/img/";
        root = document.getElementById('root');
            if (p && p.objectStore) {
                addr = p.Scada.encodeGroupAddress('0/0/202');
                p.objectStore.addListener(addr, function (obj) {
                    
                    if (obj.value !== 0) {
                        var snd0 = new Audio("" + audio0 + obj.value + "_on.mp3");
                        snd0.play();
                    }
                });
            }
//--------------------------------------------------------
 



RE: .play() and Chrome ! - JMM - 05.07.2017

Hi!
For the people which would be interested in this problem, that's why Chrome does not answer has .play() !

https://bugs.chromium.org/p/chromium/issues/detail?id=178297


Here is the solution to disable the user gesture. Big Grin Big Grin

Chrome for Android: You can disable the 'gesture required' flag by going to 'about:flags' in your chrome. Then find the flag 'disable gesture requirement for media playback' and click 'enable', at the bottom of the page box will appear that says 'Your changes will take effect the next time you relaunch Google Chrome' and a button 'Relaunch Now'. Click the button. You can now start videos via javascript.
For some reason this seems to be the best kept secret on the Internet. I searched for months before finding this.

Regards,
JMM.