Autor Beitrag
Mechwarrior15
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Mo 26.04.04 20:58 
also ich muss ein schulprojekt ausarbeiten und würde gerne in diesem ein sound-file abspielen sobald der user die maus klickt. da ich aber noch anfänger bin, findet sich hier vielleicht jemand der mir helfen kann (benutze delphi 7)
Anfänger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP
D3 Prof
BeitragVerfasst: Di 27.04.04 14:24 
Entweder mit der TMediaPlayer - Komponente oder so:

ausblenden Delphi-Quelltext
1:
uses mmsystem;					


ausblenden Delphi-Quelltext
1:
sndPlaySound(PChar(Filename),SND_ASYNC);					


SND_SYNC = Während die Datei abgespielt wird, steht die Anwendung
SND_ASYNC = Die Datei wird unabhängig vom Programm abgespielt.
SND_LOOP = Immer wieder und immer wieder
Mechwarrior15 Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Di 27.04.04 14:32 
das geht! vielen dank
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 02.05.04 20:06 
Ich möchte die Wave gerne in die EXE integrieren. Hab auch chon ne sound.rc und ne sound.res, hab aber bei dieser Anleitung folgendes Prob:

"4. Bereite den Sound zum Abspielen vor mit (z.B. in OnCreate der Form):"
:arrow: Wo ist "OnCreate"?

"6. Gib die Resource wieder frei (z.B. in OnDestroy):"
:arrow: Wo ist "OnDestroy"?
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 02.05.04 20:36 
CrazyLuke hat folgendes geschrieben:
:arrow: Wo ist "OnCreate"?
In der Entwicklungsumgebung die Form anklicken. Im ObjectInpsector (bei Standardlayout unten rechts, da wo's auch die Properties gibt) auf den Reiter "Events" wechseln. In der Liste nach "OnCreate" suchen. Doppelt drauf klcien. Im sich öffnenden CodeEditor wird die Funktion automatisch als Grundgerüst eingefügt.

CrazyLuke hat folgendes geschrieben:
:arrow: Wo ist "OnDestroy"?
In der Entwicklungsumgebung die Form anklicken. Im ObjectInpsector (bei Standardlayout unten rechts, da wo's auch die Properties gibt) auf den Reiter "Events" wechseln. In der Liste nach "OnDestroy" suchen. Doppelt drauf klcien. Im sich öffnenden CodeEditor wird die Funktion automatisch als Grundgerüst eingefügt.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 02.05.04 21:18 
Also bei mir passiert nix beim Doppelklick :roll: :cry:
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 02.05.04 21:25 
Habs doch noch irgendwie hinbekommen, dass FormCreate erscheint, Destroy will aber nicht.

Und er kennt MyHandle nicht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
uses mmsystem;

{$R sound.res}
{$R *.dfm}

procedure TForm4.FormCreate(Sender: TObject);
var
MyHandle: THandle;
begin
MyHandle := FindResource(HInstance, PChar('SOUND1'), 'WAVE');
MyHandle := LoadResource(HInstance, MyHandle);
end;
begin
SndPlaySound(LockResource(MyHandle), SND_LOOP OR SND_MEMORY);
UnlockResource(MyHandle);
end;

end.


Zuletzt bearbeitet von CrazyLuke am Mo 03.05.04 12:14, insgesamt 1-mal bearbeitet
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 11:06 
Habe jetzt an Hand dieser Anleitung folgenden Code genommen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm4.FormCreate(Sender: TObject);
var
FindHandle, ResHandle: THandle;
  ResPtr: Pointer;
begin
FindHandle:=FindResource(HInstance, 'SOUND1''WAVE');
  if FindHandle<>0 then begin
    ResHandle:=LoadResource(HInstance, FindHandle);
    if ResHandle<>0 then begin
      ResPtr:=LockResource(ResHandle);
      if ResPtr<>Nil then
        SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory);
      UnlockResource(ResHandle);
    end;
    FreeResource(FindHandle);
  end;
end;
end.


Jetzt nmeldet Delphi: "WARNING. Duplicate resource(s)"

EDIT: Da das nix mit dem eigentlichen Prob zu tun hat: delphi-forum.de/viewtopic.php?t=25100


Zuletzt bearbeitet von CrazyLuke am Mo 03.05.04 12:15, insgesamt 1-mal bearbeitet
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 12:13 
Und jetzt gehts wieder ins Ursprungsforum zurück:

ausblenden volle Höhe Delphi-Quelltext
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:
unit Unit4; 

interface 

uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ShellAPI, StdCtrls, mmsystem; 

type 
  TForm4 = class(TForm) 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    procedure FormCreate(Sender: TObject); 
    procedure Label3Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end



var 
  Form4: TForm4; 

implementation 

{$R sound.res} 
{$R *.dfm}


procedure TForm4.FormCreate(Sender: TObject); 
var 
FindHandle, ResHandle: THandle; 
  ResPtr: Pointer; 
begin 
FindHandle:=FindResource(HInstance, 'SOUND1''WAVE'); 
  if FindHandle<>0 then begin 
    ResHandle:=LoadResource(HInstance, FindHandle); 
    if ResHandle<>0 then begin 
      ResPtr:=LockResource(ResHandle); 
      if ResPtr<>Nil then 
        SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory); 
      UnlockResource(ResHandle); 
    end
    FreeResource(FindHandle); 
  end
end
procedure TForm4.Label3Click(Sender: TObject); 
begin 
ShellExecute( 0'open', PCHar ('http://www.bastardpop.co.uk'), nilnil, sw_show); 
end

end.


Erst hat erst beim Starten des Programms abgepielt, doch weil ers erst beim Anzeigen von Form4 abspielen soll hab ich ein bisschen herumexperimentiert.

Nun spielt er, nachdem ich den Code wieder zurück gesetzt habe (s.o.) gar nix mehr ab :evil:
EDIT: Nicht mehr! Lösung: "SOUND.RES" statt "sound.res"...

Aber trotzdem solls erst abgespielt werden, wenn Form4 geöffnet wird!
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 14:01 
Ich habs!
user defined image

Man darf nicht einfach im Codefenster z.B.
"procedure TForm4.FormCreate(Sender: TObject);"
in
"procedure TForm4.FormActivate(Sender: TObject);"
umändern, sondern man muss dies im ObjectInspector unter "Events" erstellen: Dies geht ancheinend mit drei schnellen Mausklicks hintereinander, jeweils auf "OnActivate", dann das weiße leere Feld daneben und nochmal "OnActivate".

Jetzt spielt ers, wenn das Fenster geöffnet wird :-D


Moderiert von user profile icontommie-lie: Bild wegen jugendgefährdenden Inhalten entfernt
=> Habs auf meinen Webspace hochgeladen, jetzt wird man nicht mehr auf dieses "Sex"bild weitergeleitet 8)


Zuletzt bearbeitet von CrazyLuke am Mo 03.05.04 16:03, insgesamt 1-mal bearbeitet
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 14:18 
Noch ne Frage: Kann man das auch eleganter lösen (Beim Schließen de Fenster soll das Programm verstummen):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction);
var
FindHandle, ResHandle: THandle;
  ResPtr: Pointer;
begin
FindHandle:=FindResource(HInstance, 'SOUND1''WAVE');
  if FindHandle<>0 then begin
    ResHandle:=LoadResource(HInstance, FindHandle);
    if ResHandle<>0 then begin
      ResPtr:=LockResource(ResHandle);
      if ResPtr<>Nil then
        sndPlaySound(PChar(ResPtr), SND_ASYNC);
      UnlockResource(ResHandle);
    end;
    FreeResource(FindHandle);
  end;
end;
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 03.05.04 14:34 
CrazyLuke hat folgendes geschrieben:
Noch ne Frage: Kann man das auch eleganter lösen (Beim Schließen de Fenster soll das Programm verstummen):
Ich verstehe nicht, wieso dein Code das Programm verstummen lassen soll :-?

Laut PSDK:
PSDK hat folgendes geschrieben:
lpszSound
A string that specifies the sound to play. This parameter can be either an entry in the registry or in WIN.INI that identifies a system sound, or it can be the name of a waveform-audio file. (If the function does not find the entry, the parameter is treated as a filename.) If this parameter is NULL, any currently playing sound is stopped.
Müsste folgendes gehen, um beim schließen des Fensters sämtliche Töne des Tasks abzubrechen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  sndPlaySound(nil0);
end;

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 14:38 
Danke. Das macht die ganze Sache doch ein wenig übersichtlicher.

"Ich verstehe nicht, wieso dein Code das Programm verstummen lassen soll"
Ich habs von folgender Seite und es funzt:
:arrow: faq.vb-hellfire.de/article.php?id=36
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 03.05.04 14:45 
CrazyLuke hat folgendes geschrieben:
"Ich verstehe nicht, wieso dein Code das Programm verstummen lassen soll"
Ich habs von folgender Seite und es funzt:
:arrow: faq.vb-hellfire.de/article.php?id=36
Da steht aber
ausblenden Quelltext
1:
2:
' Sound stoppen:
sndPlaySound vbNullString, SND_ASYNC
und nicht das, was du da mit dreifach verschachtelten IFs hingekriegt hast. vbNullString ist dabei das, was in meienm Codeschnipsel "nil" war, und auf das SND_ASYNC kann man verzichten.
Wenn aber die Ressource SOUND1 eine leere Wave-Datei ist, klappt das natürlich auch ;-)

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Mo 03.05.04 14:51 
Achso, hatte es so verstanden, dass "SndPlaySound vbNullString, SND_ASYNC" (für Stop) in den anderen Code eingebaut werden muss. Und da es mit "vbNullString" nicht geklappt hat, hab ichs einfach ein bisschen umgeändert. Und Sound1 ist auch keine leere Wave-Datei.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Di 26.10.04 11:13 
Ich habe den Sound wieder rausgenommen, nun meckert er aber, weil ich nen neuen eingesetzt habe. Anscheinend ist der alte Soudn noch nicht ganz raus, denn auch der neue hat den Namen "sound1".

Das sagt Delphi:
Zitat:
[Error] WARNING. Duplicate resource(s):
[Error] Type WAVE, ID SOUND1:
[Error] File SOUND.RES resource kept; file finsternis.res resource discarded.


Könnt ihr damit schon was anfangen oder muss ich nochwas direkt aus dem Quellcode posten?
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Di 26.10.04 12:10 
Okay, hat sich erledigt. In ner anderen Unit steckte noch ein Verweis zur alten Sounddatei drin. Wobei der Sound in der Form aber definitv nicht gebraucht wurde. Keine Ahnung, wie das da hingekommen ist....