DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Length of an audio file (Wave Audio Pack)
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 01/05/07 16:14    Post subject: Length of an audio file (Wave Audio Pack) Reply with quote

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
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 01/05/07 16:47    Post subject: Reply with quote

Look at the Length proprty of TWaveStreamAdapter class.
_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 01/05/07 18:53    Post subject: Reply with quote

I'm new to this, so could you give me an example?
Like how can I use that class in the demo sound recorder?
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 01/05/07 19:15    Post subject: Reply with quote

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:
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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 02/05/07 16:52    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 02/05/07 18:27    Post subject: Reply with quote

Use OnClose event of the main form.
_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 05/05/07 20:24    Post subject: Reply with quote

Edit: Actually I have another problem:


Code:
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 06/05/07 08:17; edited 1 time in total
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 05/05/07 23:29    Post subject: Reply with quote

Sorry, but I couldn't get what you are going to do. The logic behind is very confusing. Confused
_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Johnny_Bit
Administrator


Joined: 15 Jun 2003
Posts: 397

PostPosted: 06/05/07 06:39    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 06/05/07 08:15    Post subject: Reply with quote

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:
procedure TForm.Volumebar1Change(Sender: TObject);
begin
  Stockaudioplayer1.volume:=volumebar1.position;
end;
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 06/05/07 16:46    Post subject: Reply with quote

At designtime, set Options property to [woSetVolume].

If you use TAudioMixer, you'll have more flexibility to control volume.

_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 07/05/07 16:02    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 07/05/07 21:24    Post subject: Reply with quote

Yes!
_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Baxsan
Member


Joined: 01 May 2007
Posts: 9

PostPosted: 08/05/07 08:04    Post subject: Reply with quote

How can I do that?
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 08/05/07 12:56    Post subject: Reply with quote

Using the Position property.
Please read the ReadMe file.

_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Goto page 1, 2  Next
Page 1 of 2

Add to favorites

 
Jump to:  
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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group