![](/img/trans.png)
[英]How to print object data in Javascript using sessionStorage concepts in HTML5
[英]How to dynamically create an array within a javascript sessionstorage / HTML5
尝试通过javascript播放声音,并希望使用sessionstorage动态更改它
以下是在Android / FF Linux / Win中播放声音的简化版本,当您单击“sprite me”按钮时 - 我已在示例中包含其他按钮以在HTML5中设置和检索会话值。
http://globability.org/webapp/asprite20111124_8.html
下面的wiki有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/的Storman Stefanov的soundsprite想法 - 用于减少播放声音所需的http调用...同时稳定音质,减少断电等。
Antway在这里:你只需要看看PSEUDOCODE部分 - 其余部分正在运作
<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原型:)
哎呀...这太简单了,我自己也很接近解决这个问题,但是freelancer.com上的一位善意的自由职业者已经帮助我实现了我的一个想法,这次又做了...
而且没有进一步的麻烦:
'wordgen':EVAL( “[” + sessionStorage.globabilitykey1 + “ ”+ sessionStorage.globabilitykey2 +“]”),
这就是我所需要的 - 我一直试图做同样的事情但没有前面的“ 评估 ”和围绕论点的禁忌 ......
哦,不要忘记在尝试之前单击按钮设置值,否则扬声器没有声音;)
这是工作页面的链接,如果你想尝试,如果你想看到它的“entirity”中的代码: http ://globability.org/webapp/asprite20111201_2.html - 感谢你们那些投票的问题! !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.