試圖通過JavaScript播放聲音,並希望使用的sessionStorage如何動態創建一個JavaScript的sessionStorage內的陣列/ HTML5
下面是一個簡化版本,在Android設備/ FF的Linux播放聲音/秒動態地改變它/ Win當你點擊「sprite me」按鈕時 - 我已經包含了其他按鈕來設置和檢索HTML5中的會話值。
http://globability.org/webapp/asprite20111124_8.html
維基下方有Android手機的規格,其中它的工作原理:(三星Galaxy SII)的情況下,你有興趣
http://globability.org/wiki/doku.php?id=current_working_specs_p-tab /又見http://globability.org/wiki/doku.php?id=mobile_pointing_tablet,以獲取有關它是什麼,一個正確的想法我正在努力。
我需要的是「play soundsprite」javascript,您可以在下面的部分中從sessionstorage加載並從插入到數組中插入從sessionstorage加載的值。
我不在尋找任何改變是如何播放聲音 - 只需要在特定的javascript內部動態構建數組。
下面的代碼基於www.phpied.com/audio-sprites/上的Stoyan Stefanov的聲音想法 - 用於減少播放聲音所需的http調用...還可以穩定聲音質量,減少顫音等
Antway這裏有雲:你只需要看看僞科 - 其餘功能
<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>
如何動態地根據該值是在JavaScript中創建「wordgen」點陣任何想法sessionstorage?
整個代碼/工作示例可以在這裏看到:http://globability.org/webapp/asprite20111124_8.html
我知道的頁面是一個醜陋的爛攤子......但是這是一個alpha原型:)
***如果您覺得它有幫助,請將問題投票!*** –
http://globability.org/webapp/asprite20111205_5。html - 一個更好的例子,其中setanyvalue(arg1,arg2)函數將任意值傳遞給sessionstorage,並自動開始播放聲音sprite(用於未來版本,使用從數據庫讀取的值等) –
檢查http://globability.org /wiki/doku.php?id=mobile_pointing_tablet並查看原型部分以瞭解最新的開發情況 –