Quick links:
F-IN-BOX Delphi Edition Help >> How to How to play Flash Video (FLV) from stream
Using FlashPlayerControl you are able to play Flash Video (FLV) from external files, URL or directly from a TStream. When TFlashPlayerControl loads Flash Video no temporary files are created everything runs directly from memory. You can encrypt your video and put into application's resource - TFlashPlayerControl loads FLV without ever saving or extracting the file to disk. To play Flash Video from stream you should create flash movie that loads Flash Video from "private" URL (http://FLV/FlashVideo.flv). Flash Movie uses the following code to load Flash Video (put this in under a button in your Swf Flash Movie): [ ActionScript ]
var netConn:NetConnection = new NetConnection(); netConn.connect(null); var netStream:NetStream = new NetStream(netConn); my_video.attachVideo(netStream); netStream.setBufferTime(0); netStream.play("http://FLV/FlashVideo.flv"); When Flash tries to load Flash Video from http://FLV/FlashVideo.flv, TFlashPlayerControl provides content of FLV. Use global procedure SetGlobalOnLoadExternalResourceHandler to set handle the external resources and provide them to Flash. See the code: [ Delphi ]
type TMainForm = class(TForm) procedure FormCreate(Sender: TObject); ... private procedure OnGlobalLoadExternalResource(const URL: WideString; Stream: TStream); ... end; ... procedure TMainForm.FormCreate(Sender: TObject); begin SetGlobalOnLoadExternalResourceHandler(OnGlobalLoadExternalResource); end; ... procedure TMainForm.OnGlobalLoadExternalResource(const URL: WideString; Stream: TStream); var ResourceStream: TResourceStream; begin if URL = 'http://FLV/FlashVideo.flv' then begin ResourceStream := TResourceStream.Create(0, 'FlashVideo', 'FLV'); ResourceStream.SaveToStream(Stream); ResourceStream.Free; end; end; [ Builder C++ ]
class TMainForm : public TForm { __published: void __fastcall FormCreate(TObject *Sender); ... private: void __fastcall OnGlobalLoadExternalResource(const WideString URL, Classes::TStream* Stream); ... } ... void __fastcall TMainForm::FormCreate(TObject *Sender) { SetGlobalOnLoadExternalResourceHandler(OnGlobalLoadExternalResource); } ... void __fastcall TMainForm::OnGlobalLoadExternalResource(const WideString URL, Classes::TStream* Stream) { if (URL == WideString("http://FLV/FlashVideo.flv")) { TResourceStream* ResourceStream = new TResourceStream(0, "FlashVideo", "FLV"); ResourceStream->SaveToStream(Stream); delete ResourceStream; } } Copyright © Softanics. All rights reserved F-IN-BOX is a registered trademark of Softanics|Delphi is a trademark of Borland Software Corporation|Macromedia and Shockwave Flash are trademarks of Adobe, Inc. |