Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > help to convert code from c# to delphi


Автор: muratboy31 22.12.2010, 10:19
below...

Автор: cat512 23.12.2010, 01:57
something like that
Код

const 
  Uri: string = 'http://google.com';
var
  Req: OleVariant;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET' Url, false);
   Req.ResponseStream;

//A working with player is like above
end;

Автор: huismori 23.12.2010, 10:02
I want to use that also...
good idea  smile 

Автор: muratboy31 23.12.2010, 10:15
ofcourse u can use it if i can manage to solve it...

thanks for ur help by the way cat512 ... i tried it like that but i had problem with it...

it gives that error;
user posted image

Автор: cat512 23.12.2010, 20:53
muratboy31 could you give more details in the future PLEASE??? Once, I have already asked you about it! 
What does line give that error?

Автор: muratboy31 23.12.2010, 21:03
bold line gives error, if thats what u r asking !!! it has to speak the text using player...

Цитата

var
  Req: OleVariant;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET', Uri, false);
   Req.ResponseStream;
   MediaPlayer1.filename:=Req;   //// this line gives error
   MediaPlayer1.open;
   MediaPlayer1.play;


i want to make a speakable card app...

Автор: cat512 23.12.2010, 22:30
muratboy31 don't feel hurt to me, but you have written rubbish. Do you know what is a streaming player? How does streaming player difference from no streaming player?
Streaming player gets to itself input a stream of network data, and immediately processes and plays it for users. No streaming player gets to itself input a  filename string and tries to find the file, after tries to open and to play it. In your program, you try to play by no streaming player a network data stream. It is impossible(and incredible  smile ) The no streaming player doesn't know what is a data stream  so, and how it can process. 
Код

MediaPlayer1.filename:= {here, you must write a filename string, but no a data stream}

You can use two way for solving of your problem:
1 You can save a data stream as file to your hard drive.
2. You can use a streaming player which is ActiveX and it makes like "WinHttp.WinHttpRequest.5.1" object

Автор: muratboy31 23.12.2010, 22:37
sorry for writing rubbish  smile i am not good at explaining my self ...
do u think it would b better to use 3. party component for playing stream or download the streaming file and play ?
can u please direct me to it ? 

Автор: cat512 23.12.2010, 22:50
I was meaning when i wrote "you have written rubbish" for you that your program is wrong.
Цитата

sorry for writing rubbish

 smile  It's no awful. 
I dont know what does "3. party component" mean? Can explain me ?

Автор: muratboy31 23.12.2010, 22:52
i meant to say stream play component... i think it exist...

Автор: cat512 23.12.2010, 23:19
Ok, I Understood. Personally, I would b use streaming components,  but 
 I think a using of streaming components is more difficult than a saving  data stream  to hard drive.
You can use what is easier for you

Автор: muratboy31 23.12.2010, 23:42
i found a component but i am not sure if it will work !!!
http://www.delphiarea.com/?dl_id=28
can u please help me with it !!!
Thanks

Автор: cat512 24.12.2010, 00:14
what kind of help do you need?

Автор: muratboy31 24.12.2010, 00:27
ok if i try to save it to hdd and play after... how would i save the stream !!! it wouldnt b like saving text file !!!


Автор: cat512 24.12.2010, 02:29
There is a wrapper of win's stream in vcl. It names TOleStream. You can use it and a TMemoryStream together for a saving to hard disk

Автор: muratboy31 24.12.2010, 10:38
i found something and tried to play with it little bit but it didnt actually work... what am i doing wrong here ?

Цитата

Uses Axctrls;

Procedure TInterfaceStream.LoadFromIStream(Source : IStream);
var
  Adapt : TOLEStream;
  Buff : Byte;
  I : Integer;
begin
ADapt := TOLEStream.Create(Source);
Adapt.Position := 0;
Self.Clear;
Self.Position := 0;
For I := 0 to Adapt.Size do
  begin
    Adapt.Read(Buff, 1);
    Self.Write(Buff, 1);
  end;
Self.Position := 0;
end;

Function TInterfaceStream.GetIStream : IStream;
var
  Adapt : TStreamAdapter;
  tPos : Int64;
begin
Adapt := TStreamAdapter.Create(Self);
Adapt.Seek(0, 0, tPos);
Result := Adapt as IStream;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
  Server : ISampleCOMObj;
  temp : IStream;
  ResultStream : TInterfaceStream;
begin
Server := CreateCOMObject(Class_TSampleCOMObj) as ISampleComObj;
temp := Server.method1;
ResultStream := TinterfaceStream.Create;
ResultStream.Clear;
resultStream.Position := 0;
resultstream.LoadFromIStream(Temp);
///play temp here
end;

Автор: cat512 24.12.2010, 13:55
Код

var
   Req: OleVariant;
   Stream: TOleStream;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET', Uri, false);
   Req.Send(null);
   Stream := TOleStream.Create(IUnknown(Req.ResponseStream) as IStream);
   try
  //do something
   finally
     stream.free;
   end;
end;

Автор: huismori 24.12.2010, 15:47
nomar media palyer wouldny play it i think beacuase it is stream no ?

Автор: muratboy31 24.12.2010, 15:49
no it doesnt play it. i tried but i also this didnt work !!!

altough i stored it in to memory stream i couldnt make it to play !!!
it is saying " incompitable type tmemorystream and pwidechar "

Код

procedure TForm1.Button1Click(Sender: TObject);
var
  Req: OleVariant;
  Stream: TOleStream;
  Sound:tmemorystream;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET', Uri, false);
   Req.ResponseStream;

  Stream := TOleStream.Create(IUnknown(Req.ResponseStream) as IStream);
   try
   Sound.LoadFromStream(Stream);
   Win32Check(PlaySound(Sound, 0, SND_SYNC or SND_MEMORY));
   finally
     stream.free;
     Sound.Free;
   end;
end;

Автор: cat512 24.12.2010, 16:13
Do you look carefully what i write you???
There is a line
Код

   Req.ResponseStream;

in your code which doesn't need to be there. And this
Код

Req.Send(null);

line must be instead of that line.
What is PlaySound?

Автор: huismori 24.12.2010, 16:17
Did you find a component to plat stream ?

Автор: muratboy31 24.12.2010, 16:18
MMSystem unit attemps to plays waw files thats why i wanted to try it...

Код

Win32Check(PlaySound(Sound, 0, SND_SYNC or SND_MEMORY));


i searched for a component to play stream but non seemed to work with delphi 2010 !!!

Автор: cat512 24.12.2010, 16:44
you need to correct your program as i have pointed you and to try again

Автор: muratboy31 24.12.2010, 18:10
can u please tell me how i can play the stream ? i really tried to find components for it for no luck !!!

Автор: cat512 25.12.2010, 00:45
Show me a text of your program

Автор: muratboy31 25.12.2010, 00:59
what do u mean by text !!! do u want to c the codes ?

Код

procedure TForm1.Button1Click(Sender: TObject);
var
   Req: OleVariant;
   Stream: TOleStream;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET', Uri, false);
   Req.Send(null);
   Stream := TOleStream.Create(IUnknown(Req.ResponseStream) as IStream);
   try

  //how can i play the stream here

   finally
     stream.free;
   end;
end;




Автор: cat512 25.12.2010, 01:31
Yes, the code. Very well, you correct it.
Now, you can try to do the following
Код

procedure TForm1.Button1Click(Sender: TObject);
const
  Uri: string = 'http://api.microsofttranslator.com/v2/Http.svc/Speak?appId=' + 'My IP Id' +
         '&text=' + 'I Love You' + '&language=' + 'en';
var
   Req: OleVariant;
   Stream: TOleStream;
   Mem: TMemoryStream;
begin
   Req := CreateOleObject('WinHttp.WinHttpRequest.5.1');
   Req.Open('GET', Uri, false);
   Req.Send(null);
   Stream := TOleStream.Create(IUnknown(Req.ResponseStream) as IStream);
   try

  //how can i play the stream here
      Mem := TMemoryStream.Create;
      try
        Mem.LoadFromStream(Stream);
        Mem.SaveToFile('MyFile.tmp');    
      finally
        Mem.Free;
      end;
      MediaPlayer.FileName := 'MyFile.tmp';
      MediaPlayer.Play;
   finally
     stream.free;
   end;
end;

Автор: muratboy31 25.12.2010, 10:33
thanks alot with ur helps cat512 but there is a problem
it doesnt play the file with media player !!!



Автор: cat512 25.12.2010, 15:13
can you try to change the file exstension

Автор: muratboy31 25.12.2010, 18:04
ok this problem acurs because of tmedia player but it works with windowsmedia player ...

Автор: cat512 25.12.2010, 20:02
ok, In this case, you can use the microsoft windows media player or other players which will be able to play your file

Автор: muratboy31 25.12.2010, 20:48
yes i will do that
thank you sooo much cat512  smile 
u made my day smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)