Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 12-10-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Poder: 20
cHackAll Va por buen camino
Código Delphi [-]
function GetHeaderSize(const Value: Cardinal): Cardinal;
asm
 xor   ecx, ecx
 xchg  eax, ecx
@loop: shl  eax, 7
 or    al,  cl
 shr   ecx, 8
 jnz  @loop
end;

function GetFrameSize(const Value: Cardinal): Cardinal;
asm
 xchg al, ah
 rol eax, 10h
 xchg al, ah
end;

procedure TForm1.Button1Click(Sender: TObject);

type
 TFrame = packed record
  ID, Size: Cardinal;
  Flags: Word;
 end;

var
 hFile, Size, Buffer, FrameSize, Diff, hImage: Integer;

 Header: packed record
  ID: array [0..2] of Char;
  Version, Revision, Flags: Byte;
  Size: Cardinal;
 end;

 Frame: ^TFrame;
 Image: PChar;

begin
 hFile := _lopen('Sonata ClubDelphi.mp3', OF_READ);
 _lread(hFile, @Header, SizeOf(Header));                 // leemos los primeros 10 bytes del mp3
 Header.Version := 0; // don't needed
 if PCardinal(@Header)^ = $334449{ID3} then              // si el identificador es válido, ID3v2 está presente
  begin
   Size := GetHeaderSize(Header.Size);                   // obtenemor el tamaño "real" del cabezal
   Buffer := LocalAlloc(0, Size);                        // reservamos memoria
   Frame := Ptr(Buffer);
   _lread(hFile, Frame, Size);                           // leemos todo el ID3v2 en la memoria reservada
   while (Size > 0) and (Byte(Frame.ID) > 0) do
    begin
     FrameSize := GetFrameSize(Frame.Size);              // obtenemos el tamaño "real" del frame
     if Frame.ID = $43495041{APIC} then                  // si el frame es una imagen
      begin
       Image := PChar(Cardinal(Frame) + SizeOf(TFrame)); // obtenemos el inicio de los datos del frame
       Diff := lstrlen(@Image[1]) + 4;                   // obtenemos el tamaño del MIME y tipo
       Image[6] := '.';                                  // cambiamos '/' por '.' para "componer" el nombre de archivo
       hImage := _lcreat(@Image[1], 0);                  // creamos el archivo de imagen
       _lwrite(hImage, @Image[Diff], FrameSize - Diff);  // lo guardamos
       CloseHandle(hImage);                              // y cerramos
      end;
     Inc(FrameSize, SizeOf(TFrame));                     // consideramos el tamaño del cabezal del frame actual
     Inc(Cardinal(Frame), FrameSize);                    // ...para saltar al siguiente frame
     Dec(Size, FrameSize);
    end;
   LocalFree(Buffer);
  end;
 CloseHandle(hFile);
end;

Nota; considerando que el anterior código tuvo un proposito más informativo que práctico, aconsejo usar (por ejemplo) los componentes JEDI para manejar dicha informacion.

Saludos
__________________
RTFM > STFW > Foro > Truco > Post > cHackAll > KeBugCheckEx
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Introducción de texto sin html tags elcigarra HTML, Javascript y otros 1 04-12-2007 15:41:59


La franja horaria es GMT +2. Ahora son las 09:19:20.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi