Problèmes boucle NotifyProc
Bonjour,
J'ai deux Edit qui permettent de choisir le nombre de fois où un son doit être joué pour deux sons différents.
1er problème :
La première fois que je rentre un nombre, le son est joué (x+1) fois, sauf si 1 est le premier nombre rentré, et si je rappuie sur Play le son est joué x fois comme voulu.
Si 1 est le premier chiffre rentré, le son est joué une fois, je rentre 3, le son est joué 4 fois mais si je rePlay alors il est joué 3 fois et x fois quelque soit le nombre entré.
Si 3 est le premier chiffre rentré, le son est joué 4 fois, mais aprés quelque soit le nombre entré il joue correctement.
2ème problème :
Si je rentre x, il faut que j'appuie sur stop x fois pour que le son s'arrête.
Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
var
B : integer;
Arretautorise : boolean;
procedure TForm1.btJouerClick(Sender: TObject);
begin
Lecteur;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key <> chr(8)) and ((Key < '0') or (Key > '9')) then
begin
Key := chr(0); // Ne prend que les nombres et la touche retour
end;
end;
procedure TForm1.Lecteur;
begin
if RadioBtmont.Checked then
begin
Arretautorise := true; // Evite un bug si aucun son n'est
// lancé alors que nous appuyons sur Stop
MediaPlayer1.FileName := 'C:\Sons expérience\MONTE.wav';
MediaPlayer1.Open;
B:= StrToInt(Edit1.Text);
MediaPlayer1.Play;
if B <> 1 then
begin
MediaPlayer1.Notify := true;
MediaPlayer1.OnNotify := NotifyProc1;
end;
end;
if RadioBtdesc.Checked then
begin
Arretautorise := true;
MediaPlayer1.FileName := 'C:\Sons expérience\DESC.WAV';
MediaPlayer1.Open;
C:= StrToInt(Edit2.Text);
MediaPlayer1.Play;
if C <> 1 then
begin
MediaPlayer1.Notify := true;
MediaPlayer1.OnNotify := NotifyProc2;
end;
end;
end;
procedure TForm1.NotifyProc1(Sender: TObject);
begin
with Sender as TMediaPlayer do
begin
if NotifyValue = nvSuccessful then
begin
if B > 0 then
begin
Play;
Dec(B);
end;
end;
Notify := True;
end;
end;
procedure TForm1.NotifyProc2(Sender: TObject);
begin
with Sender as TMediaPlayer do
begin
if NotifyValue = nvSuccessful then
begin
if C > 0 then
begin
Play;
Dec(C);
end;
end;
Notify := True;
end;
end;
procedure TForm1.btArreterClick(Sender: TObject);
begin
if Arretautorise then
begin
MediaPlayer1.Stop;
end;
end; |
Merci pour vos conseils, ça fait longtemps que j'ai des problèmes avec cette partie de mon programme...