5 Replies Latest reply on Jun 22, 2016 12:51 PM by Omar Candelaria

    PocketBrowser: Play beep sound through JavaScript

    Omar Candelaria

      Hello,

       

      I have a requirement to play a beep sound whenever I get an error response from the server. I'm handling the AJAX request through JavaScript and this beep sound would have to be played on the response.

       

      On Internet Explorer I was able to implement this very easily by using either the embed or the bgsound HTML tags. I haven't been able to do the same on Pocket Browser.

       

      I've tried using the PlayWave method on the RhoMobile library (Rhomobile | Generic Preexisting JavaScript Object) ) but it's not working as expected. The sound file is a WAV and is hosted on the web server. If I try entering the file's URL as the filename, I hear the default beep sound instead of the selected WAV file. I figured that the method would only support local files. But when I tried storing the WAV file on the device and specifying the filepath, I don't hear any sound played.

       

      Do you have any examples on how to achieve this?

       

      Thanks

        • Re: PocketBrowser: Play beep sound through JavaScript
          Daniel Silva

          What device and OS are you targeting? Some of the older CE devices do not have audio hardware,  they just have a beeper. 

           

          If you just have a beeper,  you can use the code below to beep it.

           

             var Generic = new ActiveXObject("PocketBrowser.Generic");

             function beep()

             {

                 Generic.InvokeMetaFunction("Notification", "SetBeeperFrequency:1500");

              Generic.InvokeMetaFunction("Notification", "SetBeeperDuration:200");

                 Generic.InvokeMetaFunction("Notification", "SetBeeperVolume:3");

                 Generic.InvokeMetaFunction("Notification", "StateCycle:2");

             }

          1 of 1 people found this helpful
            • Re: PocketBrowser: Play beep sound through JavaScript
              Omar Candelaria

              Thanks for your quick reply.

               

              It's Pocket Browser 3.1, running on Windows Mobile 6.5 on MC9200 and MC9090. These devices have an audio device since I can hear the alert beep whenever an alert window is triggered.

               

              However, your suggestion is great for our requirement. I'm going to give it a try and let you know.

              • Re: PocketBrowser: Play beep sound through JavaScript
                Omar Candelaria

                So... the device didn't beep with your code, but now we're hearing a different beep sound when scanning.

                 

                Any suggestions on how to fix this and how to play the beep sound after changing the beep tone?

                  • Re: PocketBrowser: Play beep sound through JavaScript
                    Daniel Silva

                    Windows Mobile and Windows Embedded Handheld devices all had audio hardware. Also, on the MC9XXX you can tell by looking for a headphone jack.  If it has that, it has audio hardware.  But just the fact that the device beeps or clicks does not necessarily mean that it has audio.  The beeper is used to make these noises on non audio devices.

                     

                    These should be the default scanner beep settings.  You could change the code that you tried to these settings and the beep should be back to normal.

                        

                    Generic.InvokeMetaFunction("Notification", "SetBeeperFrequency:3000");

                        Generic.InvokeMetaFunction("Notification", "SetBeeperDuration:100");

                           Generic.InvokeMetaFunction("Notification", "SetBeeperVolume:0");

                     

                     

                    You could try some different numbers in the "StateCycle" parm, but 2 is working for the beeper for me here.

                     

                    Since you do have audio hardware, the PocketBrowser PlayWave function should work for you.

                    <script>

                      function onPlay()

                      {

                      var objGeneric = new ActiveXObject("PocketBrowser.Generic");

                     

                      objGeneric.PlayWave('\\windows\\alarm1.wav', 1);

                      }

                    </script>

                     

                     

                    If you install PocketBrowser on your PC,  there is a help file that is installed with it.

                    https://portal.zebra.com/Support/US-EN/Resolution?solutionId=92880

                    1 of 1 people found this helpful
                      • Re: PocketBrowser: Play beep sound through JavaScript
                        Omar Candelaria

                        Dan,

                         

                        Thanks for all your help. I was able to implement the requirement using the beeper. Your suggestion led me to the Notification module. Instead of hard-coding the beeper index, I'm getting it through the Notification call back.

                         

                        Rhomobile | Notification Module

                         

                        I was able to implement a multi-beep solution using the following methods. Sharing so that other people may benefit from it.

                         

                        The beep method plays multiple beeps with a delay. Each beep is decreased by 500 on the Frequency so that they would sound different. The beepOnce method is a recursive method to play a beep sound on each repetition. I wanted to use an Interval instead of Timeout, but for some reason it wasn't working on my Pocket Browser, so I had to do it this way.

                         

                        Some variables need to be declared globally, but all the other code is there...

                         

                        <META HTTP-Equiv="Notification" content="EnumNotificationsEvent:url('javascript:getBeeperIndex(%s)')">

                         

                        //*** Beeper Functions

                        //*** Used to control the beep sound when the user gets an error.

                         

                        // Initial value to be overwritten after callback.

                        var beeperIndex = -777;

                         

                        // Recursive method to play consecutive sounds using a timeout function.

                        function beepOnce() {

                         

                            SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperFrequency:" + beepFrequency);

                            SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperDuration:" + beepDuration);

                            SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperVolume:" + beepVolume);

                            SYMBOL_GENERIC.InvokeMetaFunction("Notification", "StateCycle:" + beeperIndex);

                         

                            beepFrequency = beepFrequency - 500;

                            ++iBeepReps;

                          

                            if(iBeepReps >= beepReps) {

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperFrequency:1500");

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperDuration:100");

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperVolume:0");

                                iBeepReps = 0;

                                clearTimeout(beepInterval);

                            } else {

                                beepInterval = setTimeout(beepOnce, beepDelay);

                            }

                          

                        }

                         

                        // Top level method that schedules multiple beep sounds to play depending on its parameters.

                        function beep(frequency, duration, volume, reps, delay)

                        {

                            beepFrequency = frequency;

                            beepDuration = duration;

                            beepVolume = volume;

                          

                            beepReps = reps;

                            beepDelay = delay;

                         

                            // First beep

                            beepInterval = setTimeout(beepOnce, 10);

                        }

                         

                        // Resets the scanning beep sound to its original type.

                        function resetScanningBeep(force) {

                         

                            if(force || beepInit) {

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperFrequency:1500");

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperDuration:100");

                                SYMBOL_GENERIC.InvokeMetaFunction("Notification", "SetBeeperVolume:0");

                              

                                if(beeperIndex < 0) {

                                    SYMBOL_GENERIC.InvokeMetaFunction("Notification", "Enumerate");

                                }

                              

                                beepInit = false;

                            }

                        }

                         

                        // Notification callback to get the device's beeper index.

                        function getBeeperIndex(notArr)

                        {

                             var ntfyArr = notArr;

                         

                             for(i=0; i<ntfyArr.length; i++)

                             {

                                 if(ntfyArr[i][NTFY_TYPE] == 1) {

                                     beeperIndex = ntfyArr[i][NTFY_INDEX];

                                 }

                             }

                        }

                         

                        // Calls the error beep with some predetermined parameters.

                        function errorBeep()

                        {

                            if(beeperIndex >= 0) {

                                beep(3000, 100, 3, 2, 200);

                            }

                        }

                        1 of 1 people found this helpful