Home       Goals       Download       Documentation       Support Us       Development       Job Openings       Webstore       Patrons       Contact us / Enlist      

 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

source_asprite20111121_7 [2012/03/30 01:32] (current)
Line 1: Line 1:
 +source_asprite20111121_7 - Wrong name it should be source for asprite20111124_11.html - for some reason I botched the earlier version both locally and on web... need a proper repository
 +
 +
 +<code>
 +
 +<!DOCTYPE html>
 +<html><head>
 +<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
 +  <title>Audio sprite</title>
 +
 +</head>
 +<body>
 +
 +
 +<audio id="sprite">
 +<source src="http://globability.org/webapp/sound/2011-11-21-184249.mp3"  > 
 +
 +<source src="http://globability.org/webapp/sound/2011-11-21-184249.ogg" type="audio/ogg"> <!-- oddly here video was used instead of audio (could be an "iDevice" thing) -->
 +</audio>
 +
 +<button onclick="spriteme();">sprite me</button> {seeks through a single combo file}<br>
 +
 +<button onclick="shut();">oh, shut up &#9985;</button>
 +
 +
 +<button onclick="setvalues();"> Set value </button>
 +
 + 
 +<button onclick="getvalues();"> Get value </button>
 +
 +
 +
 +<pre id="log">#: file<br>-------<br>file: "http://globability.org/webapp/2011-11-21-184249.ogg" <br>          
 +
 +// id: [start, length]
 +'blank':[0.1, 0.2],//This the first sprite apparently has to be the first defined when called first, it is a blank piece of sound in the combined sound file and needed until we can force it to play just one sound instead of seeking through the array
 +          
 +success':[13,  2,5],
 +  
 +We would like to be able to set the parameters i.e. sound bite to play dynamically - here a pseudocode example using session storage in preparation for getting the sound parameters from a database
 +
 +
 +          var wordgen[]=new Array();
 +
 +          sessionStorage.globabilitykey1;
 +          sessionStorage.globabilitykey2;
 +   strkey1=globabilitykey1+""
 +   strkey2=globabilitykey2+""
 +
 +   var gkey1=parsefloat(strkey1)
 +   var gkey2=parsefloat(strkey2)
 +
 +          'wordgen':[gkey1,gkey2]
 +         
 +
 +   and then the idea is to replace the word success with the "generated" array to allow dynamic seting of sound to play back
 +  */       
 +          'word1': [0.5, 2,36], //one
 +          'word2': [3.1,  3.0], //two
 +          'word3': [7.0,  1.82], //three
 +          'word4': [10.03, 2], //four ?br></pre>
 +
 +<script>
 +var thing = 'the thing';
 +
 +
 +function shut() {
 +    if (typeof thing.pause !== 'undefined') {
 +        thing.pause();
 +    }
 +}
 +
 +function log(what) {
 +    document.getElementById('log').innerHTML += what + "<br>";
 +}
 +
 +
 +var spriteme = function(){
 +    var sprites = {
 +          // id: [start, length]
 +    'blank':[0.1, 0.2],//This the first sprite apparently has to be the first defined when called first, it is a blank piece of sound in the combined sound file and needed until we can force it to play just one sound instead of seeking through the array
 +            
 +           'success':[13,  2,5],
 +  
 +/*
 +We would like to be able to set the parameters i.e. sound bite to play dynamically - here a pseudocode example using session storage in preparation for getting the sound parameters from a database
 +
 +
 +          var wordgen[]=new Array();
 +
 +          sessionStorage.globabilitykey1;
 +          sessionStorage.globabilitykey2;
 +   strkey1=globabilitykey1+""
 +   strkey2=globabilitykey2+""
 +
 +   var gkey1=parsefloat(strkey1)
 +   var gkey2=parsefloat(strkey2)
 +
 +          'wordgen':[gkey1,gkey2]
 +         
 +
 +   and then the idea is to replace the word success with the "generated" array to allow dynamic seting of sound to play back
 +  */       
 +          'word1': [0.5, 2,36], //one
 +          'word2': [3.1,  3.0], //two
 +          'word3': [7.0,  1.82], //three
 +          'word4': [10.03, 2], //four ?
 +            
 +        },
 +        song = ['blank', 'success'],
 +        current = 0,
 +        id = song[current],
 +        start = 0,
 +        end = sprites[id][1],
 +        int;
 +    
 +    
 +    
 +    thing = document.getElementById('sprite');
 +    thing.play();
 +    
 +    log('file: ' + thing.currentSrc);
 +    log(id + ': start: ' + sprites[id].join(', length: '));
 +    
 +    // change
 +    int = setInterval(function() {
 +        if (thing.currentTime > end) {
 +            thing.pause();
 +            if (current === song.length - 1) {
 +                clearInterval(int);
 +                return;
 +            }
 +            current++;
 +            
 +            id = song[current];
 +            start = sprites[id][0];
 +            end = start + sprites[id][1]
 +            thing.currentTime = start;
 +            thing.play();
 +            log(id + ': start: ' + sprites[id].join(', length: '));
 +
 +        }
 +    }, 10);
 +    
 +    
 +    
 +};
 +
 +
 +
 +</script>
 +
 +
 +<script type="text/javascript"> 
 +
 +function setvalues() {
 +
 +sessionStorage.globabilitykey1="13";
 +
 +sessionStorage.globabilitykey2="2,5";      
 +    
 +}
 +
 +/* I should use session storage like this
 +
 +sessionStorage.lastname="Smith";
 +document.write(sessionStorage.lastname); 
 +
 +Rather than localstorage - this way info only saved during session and all the cookie mess avoided and then fetching sound bite as below - button example works on homepage 
 +*/
 +</script> 
 +
 +
 +</script>
 +
 +
 +
 +<script type="text/javascript"> 
 +
 +function getvalues() {
 +
 +document.write(sessionStorage.globabilitykey1);
 +
 +document.write(sessionStorage.globabilitykey2);
 +}
 +</script> 
 +
 +</body></html>
 +
 +
 +</code>
  
source_asprite20111121_7.txt ยท Last modified: 2012/03/30 01:32 (external edit)
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki



The contents of this site, i.e. texts, programs and images, but not limited to these, belongs to their respective owners and are protected under international copyright treaties according to individual licensing.

Please make sure you familiarize yourself with the appropriate permissions / licenses and follow these individually before using anything you find on this site.

The Global Ability Initiative is a Non Profit venture dedicated to the development of gratis, open source software for the disabled, the sick and the needy - We aim to provide assistive software to a wide variety of people, suffering for example from Aphasia, MS, ALS, Cerebral Palsy and other disabilities as well as pushing initiatives in the field of ECG monitoring.

With reservation for changes and errors.