Length of an audio file (Wave Audio Pack)

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Length of an audio file (Wave Audio Pack)

Postby Baxsan » May 1st, 2007, 4:14 pm

How can i get the length of the currently playing (or opened) file?
Couldn't find any thread about this.

File is beeing played with the StockAudioPlayer
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 1st, 2007, 4:47 pm

Look at the Length proprty of TWaveStreamAdapter class.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Baxsan » May 1st, 2007, 6:53 pm

I'm new to this, so could you give me an example?
Like how can I use that class in the demo sound recorder?
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 1st, 2007, 7:15 pm

While recording, use Position property of the recorder component to get current recording position.

When using TAudioPlayer or TAudioRecorder (while not recording), use the Wave.Length property.

For other cases use the following example as a template. The following function returns Length of a Wave file in milliseconds.

Code: Select all
uses WaveStorage;

function WaveLength(const FileName: String): DWORD;
var
  Stream: TStream;
  Adapter: TWaveStreamAdapter;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    Adapter := TWaveStreamAdapter.Create(Stream, soReference);
    try
      Result := Adapter.Length;
    finally
      Adapter.Free;
    end;
  finally
    Stream.Free;
  end;
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Baxsan » May 2nd, 2007, 4:52 pm

Ok, thank you, I'll remember.

One non Wave Audio Package question:

What's the procedure that executes, when you close your application? I'd like to delete one file, before( or after) the program closes.
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 2nd, 2007, 6:27 pm

Use OnClose event of the main form.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Baxsan » May 5th, 2007, 8:24 pm

Edit: Actually I have another problem:


Code: Select all
function WaveLength(const FileName: String): DWORD;
var
  Stream: TStream;
  Adapter: TWaveStreamAdapter;
  filedir,todir:PAnsiChar;
  toname:string;
begin
  toname:=ExtractFilePath(Application.ExeName) + ExtractFileName('Templength.wav');
  todir:=pansichar(toname);
  filedir:=pansichar(filename);
  copyfile(filedir,todir,false);
  Stream := TFileStream.Create(toname, fmOpenRead);
  try
    Adapter := TWaveStreamAdapter.Create(Stream, soReference);
    try
      Result := Adapter.Length;
    finally
      Adapter.Free;
    end;
  finally
    Stream.Free;
  end;
  deletefile(toname);
end;


The function should copy the mainfile, name it "Templength" and to all the work with it and the delete it. The problem is that it says that it can't find the file, though it's right there.

It seems to have somekind of delay, when I remove the deleting part of the code and creat the "Templength.wav" manually, before the function executes. By the delay, I mean that it doesn't use the file that was just created (copied), but the previously created files.
Last edited by Baxsan on May 6th, 2007, 8:17 am, edited 1 time in total.
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 5th, 2007, 11:29 pm

Sorry, but I couldn't get what you are going to do. The logic behind is very confusing. :?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Johnny_Bit » May 6th, 2007, 6:39 am

it looks like he's trying to do new blank wav file with lenght of known file. Am I right?
Thou shalt write the code, not connect the bricks.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby Baxsan » May 6th, 2007, 8:15 am

That's exactly what I'm trying to do.


Edit: I made some changes and now it works properly.

But what about volume changing?

This doesn't seem to work?

Code: Select all
procedure TForm.Volumebar1Change(Sender: TObject);
begin
  Stockaudioplayer1.volume:=volumebar1.position;
end;
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 6th, 2007, 4:46 pm

At designtime, set Options property to [woSetVolume].

If you use TAudioMixer, you'll have more flexibility to control volume.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Baxsan » May 7th, 2007, 4:02 pm

Yes! It's working!

I'll propmise that this(these) will be the last question(s):

Is it true that when you pause the StockAudioPlayer, then the last position(before the pause) is stored somewhere and used, when its unpaused again?

If it's true, then is it possible to change it, while the player is paused?
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 7th, 2007, 9:24 pm

Yes!
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Baxsan » May 8th, 2007, 8:04 am

How can I do that?
Baxsan
Active Member
Active Member
 
Posts: 9
Joined: May 1st, 2007, 4:02 pm

Postby Kambiz » May 8th, 2007, 12:56 pm

Using the Position property.
Please read the ReadMe file.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Next

Return to DELPHI AREA Products

Who is online

Users browsing this forum: Bing [Bot] and 1 guest