flash播放怎样播放由swf转化为exe的文件?(100分)

  • 主题发起人 主题发起人 zhqire
  • 开始时间 开始时间
Z

zhqire

Unregistered / Unconfirmed
GUEST, unregistred user!
flash播放怎样播放由swf转化为exe的文件?
 
我也想知道!
 
很简单,在用Player播放器时,点 文件->输出就生成了exe的文件了,不依赖任何其他东东了.
 
什么意思?直接运行exe文件不就行了吗?
 
你想罐头作成鱼
 
你直接就可以播放了,exe文件本身就集成了播放器啊
 
给你贴上我写的一个单元,包括 Swf<->EXE。。。
unit FlashConv;

interface

uses
Windows, Classes, SysUtils, Forms;

type
TFileType=(ftSelf,ftExe,ftOtherExe,ftOldVerExe,ftSwf,ftSelfPlayer,ftPlayer,ftOtherPlayer,ftOldVerPlayer,ftOther);
TCovState=(csSucc,csFailed,csOldVersion,
csSourceFileNotFound,csDestFileNotFound,csLinkerFileNotFound,
csInvalidPlayer,csInvalidSwf,csInvalidExe);
TFileInfo = packed record
CommpanyName: string;
FileDescription: string;
FileVersion: string;
InternalName: string;
LegalCopyright: string;
LegalTrademarks: string;
OriginalFileName: string;
ProductName: string;
ProductVersion: string;
Comments: string;
VsFixedFileInfo:VS_FIXEDFILEINFO;
UserDefineValue:string;
end;


function isSwfExe(FileName:String):TFileType;
function ExeToSwf(Src,Dest:string;Ignore:Boolean=True):TCovState;
function SwfToExe(Src,Dest:String;Linker:string=''):TCovState;
function ExeToPlayer(Src:String;var Dest:String;Ignore:Boolean=True):TCovState;
procedure GetConvErrMsg(csState: TCovState);

function GetFileVerInfo(const FileName: string;
var info: TFileInfo;UserDefine:string=''):boolean;

var
TempFile: String;
DestFile: String;
theFileInfo: String;
Version: String;
HelpString: String;
CurrentVersion: Integer;

implementation

function isSwfExe(FileName:String):TFileType;
var
FileStream: TFileStream;
Flag: Integer;
FileInfo: TFileInfo;
FlashPlayFlag: Array[0..13] of Char;
begin

Result:=ftOther;

FileStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyWrite);
try
with FileStreamdo

begin

Seek(0,soFrombegin
ning);
ReadBuffer(Flag,SizeOf(Integer));
Flag:=Flag and $00FFFFFF;
if Flag=$00535746 then
//.swf文件开始部分标志
begin

Result:=ftSwf;
//是 .swf 文件
exit;
end;


GetFileVerInfo(FileName,FileInfo,'播放器标志');
StrLCopy(FlashPlayFlag,PChar(FileInfo.FileDescription+' '),12);
if (UpperCase(ExtractFileExt(FileInfo.OriginalFileName))<>'.OCX') and (UpperCase(FlashPlayFlag)='FLASH PLAYER') then

Result:=ftPlayer
else
if FileInfo.UserDefineValue='Flash 影院' then

begin

GetFileVerInfo(FileName,FileInfo,'支持版本');
if CurrentVersion<StrToInt(FileInfo.UserDefineValue) then

Result:=ftOldVerPlayer
else

Result:=ftSelfPlayer;
end
else
if UpperCase(ExtractFileExt(FileName))='.EXE' then

Result:=ftOtherPlayer;
{ else

begin

Result:=ftOther;
exit;
end;

}
Seek(-2*Sizeof(Integer),soFromEnd);//移至文件末
ReadBuffer(Flag,Sizeof(Integer));//并读取文件标志
if Flag=Integer($FA123456) then
//如果读到的文件标志与FA123456相同
begin

case Result of
ftPlayer: Result:=ftExe;
ftSelfPlayer: Result:=ftSelf;
ftOtherPlayer:Result:=ftOtherExe;
ftOldVerPlayer: Result:=ftOldVerExe;
else

Result:=ftOther;
end;

end;

end;

finally
FileStream.Free;
end;

end;


function ExeToSwf(Src,Dest:string;Ignore:Boolean=True):TCovState;
var
SrcStream,DestStream: TFileStream;
SwfFileSize: Cardinal;
tFT: TFileType;
begin

Result:=csFailed;

if not FileExists(Src) then

begin

Result:=csSourceFileNotFound;
exit;
end;


if not Ignore then

begin

tFT:=isSwfExe(Src);
if not (tFt in [ftSelf,ftExe,ftOtherExe]) then

begin

Result:=csInvalidExe;
exit;
end
else
if tFT=ftOldVerExe then

begin

Result:=csOldVersion;
exit;
end;

end;


SrcStream:=TFileStream.Create(Src,fmOpenRead or fmShareDenyWrite);
try
with SrcStreamdo

begin

Seek(-2*SizeOf(Integer),soFromEnd);
ReadBuffer(SwfFileSize,SizeOf(Integer));
if SwfFileSize=$FA123456 then

begin

ReadBuffer(SwfFileSize,SizeOf(SwfFileSize));
Seek(-SwfFileSize-2*SizeOf(Integer),sofromend);
DestStream:=TFileStream.Create(Dest,fmCreate);
try
DestStream.CopyFrom(SrcStream,SwfFileSize);
Result:=csSucc;
finally
DestStream.Free;
end;

end;

end;

finally
SrcStream.Free;
end;

end;


function SwfToExe(Src,Dest:String;Linker:string=''):TCovState;
var
SrcStream,DestStream,LinkStream: TFileStream;
Flag: Cardinal;
SwfFileSize: Integer;
LinkFile: String;
tState: TCovState;
tFT: TFileType;
begin

Result:=csFailed;

if not FileExists(Src) then

begin

Result:=csSourceFileNotFound;
exit;
end;


if isSwfExe(Src)<>ftSwf then

begin

Result:=csInvalidSwf;
exit;
end;


DestStream:=TFileStream.Create(Dest,fmCreate);
try
if (Linker='') or (Linker=Application.ExeName) then

begin

tState:=ExetoPlayer(Application.ExeName,DestFile);
if tState=csSucc then

LinkFile:=DestFile
else

begin

Result:=tState;
exit;
end;

end
else

begin

tFT:=isSwfExe(Linker);
case tFT of
ftSelf,ftExe,ftOtherExe:
begin

tState:=ExetoPlayer(Application.ExeName,DestFile);
if tState=csSucc then

LinkFile:=DestFile
else

begin

Result:=tState;
exit;
end
end;

ftOldVerExe:
begin

Result:=csOldVersion;
exit;
end;

ftSelfPlayer,ftPlayer,ftOldVerPlayer:
LinkFile:=Linker;
ftOtherPlayer:
begin

if MessageBox(Application.Handle,PChar('未知类型的可执行文件,您确认是一个 Flash 播放器吗?'+#13#13'按 “确定”继续转换,按“取消”放弃。'),'提示',MB_OKCANCEL+MB_ICONINFORMATION+MB_SYSTEMMODAL)=ID_CANCEL then

exit
else

LinkFile:=Linker;
end;

else

begin

Result:=csInvalidPlayer;
exit;
end;

end;

end;


if not FileExists(LinkFile) then

begin

Result:=csLinkerFileNotFound;
exit;
end;


Linkstream:=TFileStream.Create(LinkFile,fmOpenRead or fmShareDenyWrite);
try
DestStream.CopyFrom(Linkstream,0);
finally
LinkStream.Free;
end;


SrcStream:= TFilestream.Create(Src,fmOpenRead or fmShareDenyWrite);
try
DestStream.CopyFrom(SrcStream,0);
Flag:=$FA123456;
DestStream.WriteBuffer(Flag,SizeOf(Integer));
SwfFileSize:=SrcStream.Size;
DestStream.WriteBuffer(SwfFileSize,SizeOf(Integer));

Result:=csSucc;
finally
SrcStream.Free;
end;

finally
DestStream.Free;
end;

end;


function ExeToPlayer(Src:String;var Dest:String;Ignore:Boolean=True):TCovState;
var
SrcStream,DestStream: TFileStream;
SwfFileSize: Cardinal;
tFT: TFileType;
begin

Result:=csFailed;

if not FileExists(Src) then

begin

Result:=csSourceFileNotFound;
exit;
end;


if not Ignore then

begin

tFT:=isSwfExe(Src);
case tFT of
ftSelfPlayer,ftPlayer,ftOldVerPlayer,ftOtherPlayer:
begin

Result:=csSucc;
exit;
end;

ftOther,ftSwf:
begin

Result:=csInvalidPlayer;
exit;
end;

ftOldVerExe:
begin

Result:=csOldVersion;
exit;
end;

end;

end;


SrcStream:=TFileStream.Create(Src,fmOpenRead or fmShareDenyWrite);
try
with SrcStreamdo

begin

Seek(-1*SizeOf(Integer),soFromEnd);
ReadBuffer(SwfFileSize,SizeOf(Integer));
Seek(0,soFrombegin
ning);
SwfFileSize:=Size-LongInt(SwfFileSize)-2*SizeOf(Integer);

DestStream:=TFileStream.Create(Dest,fmCreate);
try
DestStream.CopyFrom(SrcStream,SwfFileSize);
Result:=csSucc;
finally
DestStream.Free;
end;

end;

finally
SrcStream.Free;
end;

end;


procedure GetConvErrMsg(csState: TCovState);
var
tmpStr:String;
begin

case csState of
csSucc: tmpStr:='转换成功!';
csFailed: tmpStr:='转换失败!';
csSourceFileNotFound: tmpStr:='源文件未找到!';
csDestFileNotFound: tmpStr:='目标文件未找到!';
csLinkerFileNotFound: tmpStr:='播放器文件未找到!';
csInvalidPlayer: tmpStr:='无效的播放器文件!';
csInvalidSwf: tmpStr:='无效的 SWF 文件!';
csInvalidExe: tmpStr:='无效的 Flash EXE 文件!';
csOldVersion: tmpStr:='不支持的高版本 Flash 影院 文件!';
end;


MessageBox(Application.Handle,PChar(tmpStr),'结果',mb_OK+mb_ICONINFORMATION+mb_SYSTEMMODAL);
end;


function GetFileVerInfo(const FileName: string;
var info: TFileInfo;UserDefine:string=''):boolean;
const
SFInfo= '/StringFileInfo/';
var
VersionInfo: Pointer;
InfoSize: DWORD;
InfoPointer: Pointer;
Translation: Pointer;
VersionValue: string;
unused: DWORD;
begin

unused := 0;
Result := False;
InfoSize := GetFileVersionInfoSize(pchar(FileName), unused);
if InfoSize > 0 then

begin

GetMem(VersionInfo, InfoSize);
Result := GetFileVersionInfo(pchar(FileName), 0, InfoSize, VersionInfo);
if Result then

begin

VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Translation, InfoSize);
VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) + IntToHex(HiWord(Longint(Translation^)), 4) + '/';
VerQueryValue(VersionInfo, pchar(VersionValue + 'CompanyName'), InfoPointer, InfoSize);
info.CommpanyName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'FileDescription'), InfoPointer, InfoSize);
info.FileDescription := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'FileVersion'), InfoPointer, InfoSize);
info.FileVersion := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'InternalName'), InfoPointer, InfoSize);
info.InternalName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalCopyright'), InfoPointer, InfoSize);
info.LegalCopyright := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalTrademarks'), InfoPointer, InfoSize);
info.LegalTrademarks := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'OriginalFileName'), InfoPointer, InfoSize);
info.OriginalFileName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductName'), InfoPointer, InfoSize);
info.ProductName := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductVersion'), InfoPointer, InfoSize);
info.ProductVersion := string(pchar(InfoPointer));
VerQueryValue(VersionInfo, pchar(VersionValue + 'Comments'), InfoPointer, InfoSize);
info.Comments := string(pchar(InfoPointer));
if VerQueryValue(VersionInfo, '/', InfoPointer, InfoSize) then

info.VsFixedFileInfo := TVSFixedFileInfo(InfoPointer^);
if UserDefine<>'' then

begin

if VerQueryValue(VersionInfo,pchar(VersionValue+UserDefine),InfoPointer,InfoSize) then

info.UserDefineValue:=string(pchar(InfoPointer));
end;

end;

FreeMem(VersionInfo);
end;

end;


end.

 
以前好像在电脑爱好者上也看过类似的代码

^_^,收藏了
 
上面的代码我试过了,有些错误老是改不了。能不能给发一份未编译的DELPHI文件?我的email:chuanxue_1999@tom.com[:(][8D][:)]
 
可以以资源文件的形式保存在.exe文件中,运行时释放出来,利用flash控间自动播放。编辑资源文件可以用brcc32.不过缺点是每一个就需要编辑一次,挺麻烦的。
 
现在我正好找到了一个swf2exe的,也调试通过了。代码如下:
先在use后声明一个函数:

///////////////////////////////// swf->exe
function Swf2Exe(S, D, F: string): string;

//S = Source file (swf)
//D = Destionation file (exe)
//F = Flash Player
var
SourceStream, DestinyStream, LinkStream: TFileStream;

flag: Cardinal;

SwfFileSize: Integer;

begin

Result := 'something error';

DestinyStream := TFileStream.Create(D, fmCreate);

try
LinkStream := TFileStream.Create(F, fmOpenRead or fmShareExclusive);

try
DestinyStream.CopyFrom(LinkStream, 0);

finally
LinkStream.Free;

end;



SourceStream := TFileStream.Create(S, fmOpenRead or fmShareExclusive);

try
DestinyStream.CopyFrom(SourceStream, 0);

flag := $FA123456;

DestinyStream.WriteBuffer(flag, SizeOf(Integer));

SwfFileSize := SourceStream.Size;

DestinyStream.WriteBuffer(SwfFileSize, SizeOf(Integer));

Result := '';

finally
SourceStream.Free;

end;


finally
DestinyStream.Free;

end;


end;


////////////////////////////////swf->exe
然后,再在某一事件中调用它,
Swf2Exe(opendialog1.FileName ,savedialog1.FileName+'.exe',ExtractFilePath(Application.Exename)+'SAFlashPlayer.exe');
当然要把'SAFlashPlayer.exe'放在根目录下
 
后退
顶部