• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1887
  • Last Modified:

Decrypt and play video from TMemoryStream

Hello,

I have encrypted video located in http server, and i want to do with it the following.
- Download and decrypt it in MemoryStream.
- Play this video from MemoryStream.

So i won't to put the video in the hard driver, i want to download, decrypt and play it in memory.
0
Mahdi78
Asked:
Mahdi78
  • 3
  • 3
1 Solution
 
jimyXCommented:
You can't download to MemoryStream. You have to assign physical destination in the local hard drive.
All the online Multimedia players download videos before playback (through buffering). Even Youtube downloads and use temp files to stream the videos.

The default path is the Temp Folder, default is:
C:\Documents and Settings\UserName\Local Settings\Temp

So you should download your video to the Temp Folder and then decrypt it and finally play it.

All the Audio/Video players require path/file location to start. Haven't seen Multimedia player that supports such streaming from Memory.
0
 
Mahdi78Author Commented:
>> You can't download to MemoryStream.

It is possible with idhttp to download to MemoryStream, like the following example

var MStrm: TMemoryStream;
begin
MStrm := TMemoryStream.Create;
  try
  IdHttp1.Get('http://localhost/video.wmv', MStrm);
  MStrm.SaveToFile('myvideo.wmv');
  Showmessage('Download finished');
  finally
  MStrm.Free;
  end;
end;

It is possible to Decrypt MemoryStream too

>> All the Audio/Video players require path/file location to start. Haven't seen Multimedia player that supports such streaming from Memory.

what about mms protocol? like this link
mms://83.221.120.201/streaming/mednetu/5455/Lez001.wmv

My idea about how to do like the following example

var MStrm1, MStrm2: TMemoryStream;
begin
MStrm1 := TMemoryStream.Create;
MStrm2 := TMemoryStream.Create;
  try
  IdHttp1.Get('http://localhost/video.wmv', MStrm1);
  MStrm2 := Decrypt(MStrm1);
  MyPlayer.Loadstream(MStrm2);
  MyPlayer.Play;
  finally
  MStrm1.Free;
  MStrm2.Free;
  end;
end;

0
 
jimyXCommented:
I don't know much about TIdhttp, but I will investigate on how it handles that exactly (i.e. does it use local temp file or it's a direct stream loading).
Ya agree, decrypting streams is not an issue, once you have your stream fully loaded and ready, you can change it easily.

MMS is a network streaming protocol which uses data packets to be sent via network, then played on the fly. It differs than downloading multimedia content to a stream.

Ciuly has developed a component which will enable you to play multimedia contents from stream:
http://www.ciuly.com/delphi/multimedia/

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22901002.html

Let's find out how it goes:
procedure TForm1.Button1Click(Sender: TObject);
var
  MStrm: TMemoryStream;
begin
  MStrm := TMemoryStream.Create;
  try
    IdHttp1.Get('http://MultimediaLink/test.avi', MStrm);
    Caption := 'Download finished';
    MCIStreamPlayer1.Stream := MStrm;
    MCIStreamPlayer1.open;
  finally
    MStrm.Free;
  end;
end;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mahdi78Author Commented:
Good links jimyX, this what i'm looking for
But unfortunately the both components don't work with Delphi 2009 and don't support wmv video,

Your code doesn't work it raise an error when MCIStreamPlayer1 get the stream, but i got the way how to load stream into MCIStreamPlayer1

You really answered to my question,  if you have or any expert has an additional comment please shoot it
0
 
jimyXCommented:
>   "components don't work with Delphi 2009"
When compiling it under Delphi 2009 and you get the errors, just change all the PAnsiChar to PChar.

>   "it raise an error when MCIStreamPlayer1 get the stream"
Let me guess, you downloaded to a temp file, converted it, then loaded it to the MCIStreamPlayer1, no?
0
 
Mahdi78Author Commented:
>> When compiling it under Delphi 2009 and you get the errors, just change all the PAnsiChar to PChar.

Oops, thank you it resolved, i was so lazy, when got errors with TMCIStreamPlayer i changed all functions PAnsiChar to PChar but i forgot to change the variable from AnsiChar to Char, when i converted my components to Delphi 2009 i changed variables Char to AnsiChar and function PChar to PAnsiChar except TMCIStreamPlayer, it work by opposite way lol, i don't know why.

DSPack still unconverted to Delphi 2009.

>> Let me guess, you downloaded to a temp file, converted it, then loaded it to the MCIStreamPlayer1, no?

I downloaded an avi from local http server like this example

procedure TForm1.Button1Click(Sender: TObject);
var
  MStrm: TMemoryStream;
begin
  MStrm := TMemoryStream.Create;
  try
    IdHttp1.Get('http://localhost/video/test.avi', MStrm);
    Caption := 'Download finished';
    MCIStreamPlayer1.Stream := MStrm;
    MCIStreamPlayer1.open;
  finally
    MStrm.Free;
  end;
end;

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now