Sunday, December 22, 2019

so, i was completely right about approaching the javascript frontend like it's a...script...rather than trying to fuck around with objects. and, the right error listener was the onerror, too.

let's do this one more time.

so, i posted the thing here, initially:
http://dsdfghghfsdflgkfgkja.blogspot.com/2019/11/im-going-to-post-last-update-to-this.html

the changes are as follows.

//this is the html5 control. it now checks for each of the filetypes, and either plays the file or throws an error.
<audio autoplay controls  style="width:500px;height:50px"  id="Player">
<source id=flac src="path to first flac file" type="audio/flac">
<source id=mp3 src="path to first mp3 file" type="audio/mp3">
<source id=aac src="path to first m4a file" type="audio/mp4">
<source id=wav src="path to first wav file" type="audio/wav">
<source id=ogg src="path to first ogg file" type="audio/ogg">
</audio>

//here is the script.
<script>
var elm = 0;      //this is the counter. the snippet used elm. i don't really know why. you can change it to c...
var t=0;  //this is a boolean to prevent infinite looping through the error handling
var Player = document.getElementById('Player');   //this gets the player from the html doc

//so, let's try to set the file paths to mp3 files
var nextsrc = [array of mp3 file paths];

//if they aren't accessible, the player will throw an error
Player.onerror=function(){
     if (t=0){
          nextsrc = [array of flac file paths];  //well, let's try flac, then.
          Player.src=nextsrc[elm];  //then, let's set the path
          Player.play();   //try to play. if it works, great. if not, it errors:.
          Player.onerror=function(){  
               nextsrc = [array of ogg file paths];  //well, if it's not mp3 & not flac, maybe it's ogg...
               Player.src=nextsrc[elm];  //so, set the path
               Player.play();  /try to play. if it doesn't work, it errors:
               Player.onerror=function(){ 
                    nextsrc = [array of m4a file paths]; //next, try the m4as
                    Player.src=nextsrc[elm];  //set the path again
                    Player.play();  //try to play. if it doesn't work, it'll error one more time...
                    Player.onerror=function(){
                         nextsrc = [array of wav file paths];  //last try.
                         Player.src=nextsrc[elm];  //set the path
                         Player.play();  //play
                         Player.onerror=function(){t=1;}  //if it's still erroring, give up
                   }
               }
          }
     }
}
</script>

=============

the rest is the same.

i think that's done, now, so i should get that uploaded soon and should be able to move forward pretty quickly. just some more testing, still...