我創建了使用網絡音頻API生成莫爾斯電碼聲音的代碼。摩爾斯電碼聲音正在運作完美。我想用這種聲音來刷新屏幕的一部分。只有兩個聲音點(。)和短劃線( - )。我想通過閃爍屏幕的一部分來顯示消息。 我試圖將div的背景顏色設置爲黑色,然後隱藏/顯示div來給出閃光效果。但它不工作作爲expected.please幫助我....在此先感謝... 我嘗試這樣做:Flash屏幕的一部分使用用於莫爾斯電碼(音頻上下文)的網絡音頻API創建的聲音
$(document).ready(function() {
\t var context = new (window.AudioContext || window.webkitAudioContext());
\t var O= new MorseNode(context,20);
\t O.connect(context.destination);
\t O.playString(1,'.-- -..');
});
function MorseNode(ac, rate) {
// ac is an audio context.
this._oscillator = ac.createOscillator();
this._gain = ac.createGain();
this._gain.gain.value = 0;
this._oscillator.frequency.value = 550;
this._oscillator.connect(this._gain);
if(rate == undefined)
rate = 20;
this._dot = 1.2/rate; // formula from Wikipedia.
this._oscillator.start(0);
}
MorseNode.prototype.connect = function(target) {
return this._gain.connect(target);
}
MorseNode.prototype.playChar = function(t, c) {
for(var i = 0; i < c.length; i++) {
switch(c[i]) {
case '.':
$('#flashBlock').hide(); //I tried this to flash the screen.
this._gain.gain.setValueAtTime(1.0, t);
t += this._dot;
this._gain.gain.setValueAtTime(0.0, t);
$('#flashBlock').show();
break;
case '-':
$('#flashBlock').hide();
this._gain.gain.setValueAtTime(1.0, t);
t += 3 * this._dot;
this._gain.gain.setValueAtTime(0.0, t);
$('#flashBlock').show();
break;
}
t += this._dot;
}
return t;
}
MorseNode.prototype.playString = function(t, w) {
w = w.toUpperCase();
for(var i = 0; i < w.length; i++) {
if(w[i] == ' ') {
t += 3 * this._dot; // 3 dots from before, three here, and
// 1 from the ending letter before.
}
else if(w[i] != undefined) {
t = this.playChar(t, w[i]);
t += 2 * this._dot;
}
}
return t;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<html>
<div id="flashBlock" style="Background:black;display:none;height:100px;width:100px">
\t \t </div>
</html>
它的工作原理perfect..I感謝您的快速response..Thankü這麼多! :) – user3357709
動畫不像flash效果..所以,我修改flashloop函數中的隱藏/顯示代碼爲「flashBlock.show()。delay(duration).fadeOut(-80);」... ...所有代碼的其餘部分是按預期工作..再次感謝:) – user3357709
聲音和閃光燈不能同時工作。我想保持該塊閃爍的聲音。如果聲音播放3秒鐘,則閃光燈應保持可見狀態3秒鐘,然後立即隱藏該區塊。幫助plzzzzzz – user3357709