Autor Beitrag
bonanza
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Di 20.12.05 22:07 
hi,
wie kann ich eine WAV oder MP3 datei zu einer res datei machen, sodass dich diese im programmm nutzen kann...(also, dass ich keine weitere dateien mehr habe außer die exe)?

danke schonmal im voraus
bonanza
Limster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72


Delphi 5 & 7 Enterprise
BeitragVerfasst: Mi 21.12.05 16:14 
Titel: Hi!
Hi!

Das in die Res-Datei reingeben ist kein Problem:

Einfach eine mp3files.rc Datei anlegen, in diese schreibst du:

ausblenden Quelltext
1:
mp3Test RCDATA LOADONCALL MOVEABLE DISCARDABLE "C:\MP3STOINCLUDE\TEST.MP3"					


so nun musst du die .rc - Datei öffnen (mit einem ResourceCompiler, sollte bei delphi dabei sein,
bzw müsst einfach doppelklich auf die .rc Datei reichen) und schon hast du eine mp3files.res

Das laden im Programm ist dann auch nicht so schwer .. in etwa so:

einfach LoadBytesFromRessourceName('mp3Test');

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:
28:
type
  TBByteArray = Array of byte;


(* +======================================================================+ *)
implementation

{$R mp3files.RES}


(* +----------------------------------------------------------------------+ *)
function LoadBytesFromRessourceName(aResName: String): TBByteArray;
var
  resHnd           : HRsrc;
  memHnd           : HGlobal;
  p                : Pointer;
  size             : Integer;
begin
  resHnd := FindResource(HInstance, PChar(aResName), RT_RCDATA);
  Assert(resHnd <> 0, 'BResUtils.LoadBytesFromRessourceName');
  memHnd := LoadResource(HInstance, resHnd);
  p := LockResource(memHnd);
  size := SizeofResource(HInstance, resHnd);
  SetLength(result, size);
  Move(p^, result[0], size);
  UnlockResource(memHnd);
  FreeResource(memHnd);
end;


so in diesem Fall hast du das in einem Array .. geht natürlich auch in einen MemoryStream..
das Problem ist das Abspielen... geht maximal per DirectShow und das sehr schwer und wurde
noch nicht gut und stabil gelöst..

also wenn du schon nicht weisst wie eine Ressource anzulegen ist, wirds
mit dem Abspielen der Ressource sehr schwer für dich..

ich hoffe dir weitergeholfen zu haben..
grüsse, limbo

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
nikita
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mi 28.12.05 21:04 
realy good function, thanks Limster :D

do you have an idea if it's possible to do the same for a DLL ?

i mean load the dll from the ressource to the memory, and use it ?
koller1
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 216

WIN XP
D7 Ent
BeitragVerfasst: Sa 14.01.06 11:40 
Soweit hat alles geklappt, aber wie kriege ich diese Datei, die durch Limsters-Code ausgelesen wird erstmal extern abgespeichert, um sie dann normal zu spielen?

_________________
PLEASE INSERT SYSTEM DISK AND PRESS ENTER!
Und wenn du nicht gestorben bist, presst du noch heute! ;)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 14.01.06 13:44 
Ich könnte mir denken, dass es so gehen würde:

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:
var
mem:TMemorystream;

function LoadBytesFromRessourceName(aResName: String): TMemorystrean;
var
  resHnd           : HRsrc;
  memHnd           : HGlobal;
  p                : Pointer;
  size             : Integer;
begin
  resHnd := FindResource(HInstance, PChar(aResName), RT_RCDATA);
  Assert(resHnd <> 0, 'BResUtils.LoadBytesFromRessourceName');
  memHnd := LoadResource(HInstance, resHnd);
  p := LockResource(memHnd);
  size := SizeofResource(HInstance, resHnd);
  SetLength(result, size);
  Move(p^, result[0], size);
  UnlockResource(memHnd);
  FreeResource(memHnd);
end;

//in irgendeine Procedure:
mem:=Tmemorystream.create;
mem:=LoadBytesFromRessourceName('BVBrulez.res');
mem.savetofile(extractfilepath(paramstr(0))+'BVbrulez.mp3');
mem.free;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Sa 14.01.06 13:54 
Meiner Meinung nach ist dieser Code zu umständlich für dein Vorhaben. Es reicht eigentlich eine .RC-Datei mit folgendem Inhalt:
ausblenden Quelltext
1:
1 WAVE "wavedatei.wav"					

und folgender Aufruf im Programm:
ausblenden Delphi-Quelltext
1:
  PlaySound(PChar(1), hInstance, snd_Resource or snd_Memory or snd_Async);					


Allerdings muss in diesem Fall die Datei eine Wave-Datei sein (kann aber trotzdem mit einem MP3-Codec komprimiert sein).

Alstar
koller1
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 216

WIN XP
D7 Ent
BeitragVerfasst: Sa 14.01.06 14:05 
@Alstar

Ist auch eine Möglichkeit, aber ich kann mit der Funktion (PlaySound.....) doch dann nicht die Funktionen des Mediaplayers nutzen, oder? Wie OnNotify usw. Außerdem sind wave-Dateien doch riesig (ca.20MB??)

MFG
koller1

_________________
PLEASE INSERT SYSTEM DISK AND PRESS ENTER!
Und wenn du nicht gestorben bist, presst du noch heute! ;)