尝试通过javascript播放声音,并希望使用sessionstorage
动态更改声音以下是在Android / FF Linux / Win中播放声音的简化版本,当你点击“sprite me button”时 - 我已经在示例中包含了其他按钮来设置和检索HTML5中的会话值。 / p>
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了解我正在做的事情。
我需要的是在下面的部分中看到“播放soundsprite”javascript从sessionstorage加载并插入从插入到数组中的sessionstorage加载的值。
我不是在寻找声音播放方式的任何变化 - 只需要在特定的javascript中制作动态构建的数组。
以下代码基于Stoyan Stefanov撰写的www.phpied.com/audio-sprites/中的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原型:)
答案 0 :(得分:1)
唉......这太简单了,我自己也很接近解决这个问题了,不过在freelancer.com上有一位善意的自由职业者,这位曾帮助我实现其中一个想法的人,这次又做了一次...... / p>
没有进一步的麻烦:
'wordgen':EVAL( “[” + sessionStorage.globabilitykey1 + “ ”+ sessionStorage.globabilitykey2 +“]”),
这就是我所需要的 - 我一直试图做同样的事情,但前面没有“ eval ”而且参数周围没有 paranthesis .... / p>
哦,不要忘记在尝试前单击按钮设置值,否则扬声器没有声音;)
以下是工作页面的链接,如果你想尝试,如果你想看到它的“完整性”中的代码:http://globability.org/webapp/asprite20111201_2.html - 感谢你们那些投票的问题!!!