Autor Beitrag
AlexII
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 180



BeitragVerfasst: Mo 23.03.09 15:23 
Hallo,
ich verwende für die Streamaufnahme (netradio - Beispiel von bass.dll) folgenden Code:

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:
var
  FileStream :   TFileStream;
  FileNeme   :   String;      // <= C:\test.mp3


function Get_AppPath : string;
begin
  result:= ExtractFilePath( ParamStr( 0 ) );
end;


procedure StatusProc(buffer: Pointer; len, user: DWORD); stdcall;
begin
  if (buffer <> nil) and (len = 0) then
    SendMessage(win, WM_INFO_UPDATE, 8, DWORD(PChar(buffer)));

  if (FileNeme = '') then
    exit;
  if (FileStream = nil) then
      FileStream:= TFileStream.Create(FileNeme, fmCreate); // create the file
  if (buffer = nil) then
      FileStream.Free // finished downloading
  else
      FileStream.Write(buffer^, len);
end;


function OpenURL(url: PChar): Integer;
var ....
begin
  FileNeme:=  Get_AppPath + Form1.Filename_Edit.Text;
  ...
end;


Jetzt würde ich mal wissen wie ich am besten die Aufnahme stoppen kann und wieder Aufnehmen. Hab mit das Stoppen mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
FileStream.Free;
end;

versucht, aber das Prog stürzt ab. :gruebel:
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 23.03.09 15:27 
Der Abstürz dürfte damit begründet sein, dass du den Stream freigibst, er danach aber nicht Nil ist. D.h. der nächste Schreibzugriff baut dann eine AV.
Machbar wäre das mit FreeAndNil, aber dann würde beim nächsten ankommenden Datenblock der Filestream neu erzeugt und womöglich das alte gelöscht.

Warum nimmst du nicht eine weitere Property/Variable, in der gespeichert wird, ob gerade aufgenommen wird oder nicht? Die fragst du in der StatusProc ab, und speicherst die Daten nur dann, wenn der Wert True ist.

_________________
We are, we were and will not be.
AlexII Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 180



BeitragVerfasst: Mo 23.03.09 15:38 
Hab leider keine Ahnung wie es gehen soll. Der Code zum Aufnehmen ist auch nicht von mir.
Und einfach irgendwie mit einem Befehl zu stoppen geht nicht? Schade...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 23.03.09 15:54 
Einfach so: ?
ausblenden 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:
procedure StatusProc(buffer: Pointer; len, user: DWORD); stdcall;
begin
  if (buffer <> nil) and (len = 0) then
    SendMessage(win, WM_INFO_UPDATE, 8, DWORD(PChar(buffer)));

  if (FileNeme = '') then
    exit;
  if JoIchWillAufnehmen then
  begin
    if (FileStream = nil) then
        FileStream:= TFileStream.Create(FileNeme, fmCreate); // create the file
    if (buffer = nil) then
        FileStream.Free // finished downloading
    else
        FileStream.Write(buffer^, len);
  end;
end;

procedure TForm1.ButtonStopClick(Sender: TObject);
begin
  JoIchWillAufnehmen = False;
end;

procedure TForm1.ButtonStartClick(Sender: TObject);
begin
  JoIchWillAufnehmen = True;
end;

_________________
We are, we were and will not be.
AlexII Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 180



BeitragVerfasst: Mo 23.03.09 16:09 
Irgendwie finde ich nix über Property... geht es auch einfach mit einer Variable?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 23.03.09 16:13 
Wieso sollte das nicht gehen?

_________________
We are, we were and will not be.
AlexII Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 180



BeitragVerfasst: Mo 23.03.09 16:17 
Na weil du über property gesprochen hast. Ok