0 Replies Latest reply on Jan 6, 2018 8:00 PM by ganduking

    Temporary way to Suppress Alert messages?

    ganduking

      I have been working on this app in my spare time, which has been driving me crazy for months on one last part that makes it ready for release.

       

      Most of the code is written by me in Javascript.  But I had to use some open source code (nativeaudio.js) to get multi-channel sound.  As when I convert it to an Android App with Phonegap I can't use those good old audio tags since sound is played differently.  That was a whole project in itself finding a way to do it, but we're passed that now.

       

      Now the only issue is when you exit the app and go back into it and error message pops up saying "a reference already exist for the specified audio id".  Which is likely because trying to reiniatlize the nativeaudio.js module again.  Which is harmless message as the app still works.  However it just doesn't look aethetically polished for a released product.

       

      I've been tearing my hair out to supress that error message and have been trying everything like error catching or capturing the event when the back button is pressed and storing that event in a variable and doing things on a different path.

       

      I just really want to find a way to supress pop ups happening for a certain amount of time and re-enabling them.  Since probably error catching is not working since not technically an error.  Any easy way to do this?

       

      Attached below is a link which has the source code and compiled / packaged APK file.  You can only really see this message pop if you load up the APK on android and then exit the up with the back button (Or in my case I'm using NOX emulator and I hit ESC) and then reclick on the app where the message pops up. 

       

      Link with source and APK : http://soulmeld.com/mumbo-jumbo/mumbo-jumbo-source.zip

       

      The app will just show a blank screen and make a quick sound that sounds like a car door opening when you open the app.  It does more obviously, however I strip down the code to just simplify it to the last problem.  Don't really want to make any other changes such as not using the nativeaudio.js since again spent amount of months on that doing this project on the side, while balancing with my full time job.

       

      The main index source code is also below.   Again a stripped down version just to get to the core of the problem.

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>

              <script type="text/javascript">

                  window.onerror = function(message, url, lineNumber) { 

                      // code to execute on an error 

                      return true; // prevents browser error messages 

                  };

              </script>

       

       

       

       

              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

              <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

       

       

              <title>Gumbo Dumbo</title>

       

       

      </head>

       

       

      <body onload="onLoad()">

        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

        <script type="text/javascript" src="nativeaudio.js"></script>

       

       

       

      <script type="text/javascript">

       

       

              localStorage.BackButtonPressed = 0;

      localStorage.ResumeApp = 0;

      localStorage.AppPaused = 0;

      var VarBackButtonPressed = 0;

              var VarResumeApp = 0;

      var VarAppPaused = 0;

       

       

       

       

      if(typeof(localStorage.AlreadyInitialized) !== undefined) {

      try{

      app.initialize();

      } catch(e)

      {

       

       

      }

          AlreadyInitialized = 1;

          localStorage.AlreadyInitialized = 1;

      }

       

          </script>

       

              <script type="text/javascript" charset="utf-8">

       

       

                          function onDeviceReady() {

                             

                                      console.log(Media);

                                      console.log(Media2);

                          }

       

       

                          function onLoad() {

                          document.addEventListener("deviceready", onDeviceReady, false);

       

       

                          localStorage.BackButtonPressed = 0;

                          localStorage.ResumeApp = 0;

                          localStorage.AppPaused = 0;

                          var VarBackButtonPressed = 0;

                          var VarResumeApp = 0;

                          var VarAppPaused = 0;

                          } 

                         

                     

                          // Audio player

                          //

                          var my_media = null;

                          var mediaTimer = null;

       

       

                          // Play audio

                          //

                          function playAudio(src) {

                                 

                              if (my_media == null) {

                                  my_media = new Media(src, onSuccess, onError);

                              }

                              my_media.play();

       

       

                              if (mediaTimer == null) {

                                  mediaTimer = setInterval(function() {

                                      // get my_media position

                                      my_media.getCurrentPosition(

                                          // success callback

                                          function(position) {

                                              if (position > -1) {

                                                  setAudioPosition((position) + " sec");

       

       

                                     

                                                                          var WhichSong = Math.floor(Math.random()*5)

                                                          playAudio(SendSrcPgn);

                                                 

                                              }

                                          },

                                          // error callback

                                          function(e) {

                                              console.log("Error getting pos=" + e);

                                              setAudioPosition("Error: " + e);

                                          }

                                      );

                                  }, 1000);

                              }

                          }

       

       

       

       

                          function playAudio2(src) {

                              if (my_media2 == null) {

                                  my_media2 = new Media(src, onSuccess, onError);

                              }

                              my_media.play();          

                          }

       

       

                         

                          function onSuccess() {

                                      console.log("playAudio():Audio Success");

                                  }

       

       

                          function onError(error) {

                                      alert('code: '    + error.code    + '\n' +

                                      'message: ' + error.message + '\n');

                                  }

       

       

                          function setAudioPosition(position) {

                                  document.getElementById('audio_position').innerHTML = position;

                                  }

       

       

       

      </script>

      </body>

      </html>