J'ai créé un code pour générer du son morse à l'aide de l'API web audio. Le son du code Morse fonctionne parfaitement. Je voulais faire clignoter une partie de l'écran avec ce son. Il n'y a que deux sons (.) Et un tiret (-). Je voulais montrer un message en faisant clignoter une partie de l'écran. J'ai essayé de définir la couleur d'arrière-plan de div comme noir, puis masquer/montrer cette div pour donner un effet de flash. mais cela ne fonctionne pas comme expected.please me aider .... Merci à l'avance ... Je essayé ceci:Flash Partie de l'écran Avec son créé à l'aide de l'API audio web pour le code Morse (contexte audio)
$(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>
Il fonctionne perfect..I apprécient votre response..Thank rapide u so much !! :) – user3357709
L'animation n'était pas comme l'effet flash .. donc, j'ai modifié hide/show code dans la fonction flashloop comme "flashBlock.show(). Delay (durée) .fadeOut (-80);" ... reste du code est fonctionnant comme prévu .. merci encore :) – user3357709
son et flash ne fonctionne pas simultanément. Je veux garder ce bloc qui clignote avec ce son. Si le son est en cours de lecture pendant 3 secondes, ce flash doit rester visible pendant 3 secondes, puis masquer instantanément ce bloc. help plzzzzzz – user3357709