Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:16:37+00:00 2026-05-27T08:16:37+00:00

Trying to play a sound via javascript and want to change it dynamically using

  • 0

Trying to play a sound via javascript and want to change it dynamically using sessionstorage

The following is a simplified version that plays sound/s in android/FF Linux/Win when u click the “sprite me button” – I’ve included other buttons for the example to set and retrieve session values in HTML5.

http://globability.org/webapp/asprite20111124_8.html

The wiki below has Android phone specs where it works: (Samsung Galaxy SII) in case you’re interested

http://globability.org/wiki/doku.php?id=current_working_specs_p-tab / also see http://globability.org/wiki/doku.php?id=mobile_pointing_tablet to get a proper idea about what it is that I am working on.

What I need is to have the “play soundsprite” javascript that you can see below in the following section load from sessionstorage and insert values loaded from sessionstorage inserted into an array.

I am not looking for any changes is how the sound is played back – just need to make a dynamically built array work from within the particular javascript.

The code below is based on the soundsprite idea from http://www.phpied.com/audio-sprites/ by Stoyan Stefanov – made to reduce the http calls needed for playing sounds… Also stabilizes the sound quality, less choppy sound etc.

Antway here goes: YOU ONLY NEED TO LOOK AT PSEUDOCODE SECTION – The rest is functioning

<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.5], //This the first sprite, it has to be the first defined and is 
called first, it is a blank piece of sound in the combined sound file and needed as of 
now.

'success':[13,  2,5],

/* I 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


'wordgen'[null,null]; 
//this array should be dynamically built from values read from the two session storage keys not sure you need the new thing in HTML5

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 array success in the script with the "generated" 
array 'wordgen' to allow dynamic seting of sound to play back  */       

//the following are sound bites from the collection of soundsprites the site plays from

'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'], 
//here you're setting the playback sequence (this is where I would like to replace 'success' with 'wordgen'
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>

Any ideas on how to dynamically create the ‘wordgen’ array within the javascript based on the values is sessionstorage ?

The whole code/working example can be seen here: http://globability.org/webapp/asprite20111124_8.html

I know the page is one ugly mess… but this is an alpha prototype 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:16:38+00:00Added an answer on May 27, 2026 at 8:16 am

    Argh… it was sooooo simple, I was this close to solving it myself, however a kind freelancer at freelancer.com who has perviously helped me getting one of my ideas to work did it again this time…

    And without further ado:

    ‘wordgen’:eval(“[“+sessionStorage.globabilitykey1+”,”+sessionStorage.globabilitykey2+”]”),

    That was what I needed – I had been trying to do the same but without the ” eval ” in front and the paranthesis around the arguments….

    Oh and don’t forget to set the value by clicking the button before you try or there will be no sound coming out of your speakers 😉

    Here’s a link to the working page if you care to try and if you want to see the code in it’s “entirity”: http://globability.org/webapp/asprite20111201_2.html – Thanks to those of you voting the question up!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play dynamically few mp3 sounds using AVAudioPlayer. The following code
I'm trying to play a sound based on which button is pressed using AVAudioPlayer.
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I'm trying to play a wav sound that stored in byte array called bytes.
I'm trying to play only part of a sound using FMOD, say frames 50000-100000
I'm trying to play background music along with sound effects using Qt. However, I
I am trying to embed a sound in an auction website. I want that
I am trying to play 6 seperate .mp3 sound files using instances of AVAudioPlayer.
I'm trying to play a sound on a button click i'm using: -(IBAction)sound {
I am trying to play a sound file using : gst-launch playbin uri=some URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.