 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Anthony Guest
|
Posted: Fri Nov 10, 2006 9:13 am Post subject: Using TMediaPlayer inside of my own class. |
|
|
Hi all,
I am trying to create my own class as below but I have one problem and
two questions.
If you have any ideas about these, please leave your comment. It would
be greatly appreciated.
Problem #1:
MediaPlayer1.Open;
this line occurred CPU error from Delphi IDE at run time which is
saying "integer divide by zero at.".
As you can see below, I was trying to use TMediaPlayer inside of my own
class. I guess I made
something wrong in my codes. Please tell me what was wrong.
Question #1:
in case of my class definition, is this okay to call merely inherited
in constructor and destructor?
inherited Create;
inherited Destroy;
Question #2:
I assigned "self" from TForm1 into TMediaPlayer as parent window.
Of course, there is no error but I want to make sure if I was right.
The below is the codes from Unit1 and class unit.
///////////////////////////////// Unit1
var
Form1: TForm1;
implementation
uses RecordRadio_;
var RecordRadio1: TRecordRadio;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
RecordRadio1 := TRecordRadio.Create(Self);
RecordRadio1.Start;
RecordRadio1.Duration := 2;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
RecordRadio1.Free;
end;
///////////////////////////////// RecordRadio class unit
unit RecordRadio_;
interface
uses MPlayer, SysUtils, ExtCtrls, Classes, Controls;
type
TRecordRadio = class
MediaPlayer1: TMediaPlayer;
private
FDuration: Integer;
FRate: Longint;
FResolution: Word;
FChannels: Word;
FStartTime: TDateTime;
function Get_FileName: String;
function Get_FilePath: String;
public
constructor Create(AOwner:TComponent);
destructor Destroy;
procedure Start;
procedure Stop;
// Read inside and write outside.
property Channels: Word write FChannels default 2;
property Resolution: Word write FResolution default 16;
property Rate: Longint write FRate default 44100;
property Duration: Integer write FDuration default 1; // in min.
// Read outside and write outside.
property StartTime: TDateTime read FStartTime write FStartTime;
// Need internal actions.
property FileName: String read Get_FileName;
property FilePath: String read Get_FilePath;
procedure CreateDummyWaveFile;
end;
implementation
{ TRecordRadio }
procedure TRecordRadio.CreateDummyWaveFile;
type
TWavHeader = record
rId : longint;
rLen : longint;
wId : longint;
fId : longint;
fLen : longint;
wFormatTag : word;
nChannels : word;
nSamplesPerSec : longint;
nAvgBytesPerSec : longint;
nBlockAlign : word;
wBitsPerSample : word;
dId : longint;
wSampleLength : longint;
end;
var
wf : file of TWavHeader;
wh : TWavHeader;
begin
wh.rId := $46464952;
wh.rLen := 36;
wh.wId := $45564157;
wh.fId := $20746d66;
wh.fLen := 16;
wh.wFormatTag := 1;
wh.nChannels := FChannels;
wh.nSamplesPerSec := FRate;
wh.nAvgBytesPerSec := FChannels * FRate * ( FResolution div ;
wh.nBlockAlign := FChannels*( FResolution div ;
wh.wBitsPerSample := FResolution;
wh.dId := $61746164;
wh.wSampleLength := 0;
AssignFile(wf,'c:\tmp.wav');
Rewrite(wf);
Write(wf,wh);
CloseFile(wf);
end;
constructor TRecordRadio.Create(AOwner: TComponent);
begin
inherited Create;
MediaPlayer1 := TMediaPlayer.Create(AOwner);
MediaPlayer1.Parent := TWinControl(AOwner);
end;
destructor TRecordRadio.Destroy;
begin
inherited Destroy;
MediaPlayer1.Free;
end;
function TRecordRadio.Get_FileName: String;
begin
end;
function TRecordRadio.Get_FilePath: String;
begin
end;
procedure TRecordRadio.Start;
begin
CreateDummyWaveFile;
// MediaPlayer1.Visible := False;
FStartTime := Time;
if FileExists( 'c:\tmp.wav' ) then
begin
MediaPlayer1.DeviceType:= dtAutoSelect;
MediaPlayer1.FileName:= 'c:\tmp.wav';
////////////////////////////////////////////////////////////////// This
code raised CPU error at run-time.
MediaPlayer1.Open;
MediaPlayer1.StartRecording;
MediaPlayer1.Stop;
end;
end;
procedure TRecordRadio.Stop;
begin
MediaPlayer1.Stop;
end;
end. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|