| View previous topic :: View next topic |
| Author |
Message |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 01/05/07 16:14 Post subject: Length of an audio file (Wave Audio Pack) |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 01/05/07 16:47 Post subject: |
|
|
Look at the Length proprty of TWaveStreamAdapter class.
_________________ Kambiz
 |
|
| Back to top |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 01/05/07 18:53 Post subject: |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 01/05/07 19:15 Post subject: |
|
|
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 |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 02/05/07 16:52 Post subject: |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 02/05/07 18:27 Post subject: |
|
|
Use OnClose event of the main form.
_________________ Kambiz
 |
|
| Back to top |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 05/05/07 20:24 Post subject: |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 05/05/07 23:29 Post subject: |
|
|
Sorry, but I couldn't get what you are going to do. The logic behind is very confusing.
_________________ Kambiz
 |
|
| Back to top |
|
 |
Johnny_Bit Administrator
Joined: 15 Jun 2003 Posts: 397
|
Posted: 06/05/07 06:39 Post subject: |
|
|
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 |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 06/05/07 08:15 Post subject: |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 06/05/07 16:46 Post subject: |
|
|
At designtime, set Options property to [woSetVolume].
If you use TAudioMixer, you'll have more flexibility to control volume.
_________________ Kambiz
 |
|
| Back to top |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 07/05/07 16:02 Post subject: |
|
|
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 |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 07/05/07 21:24 Post subject: |
|
|
Yes!
_________________ Kambiz
 |
|
| Back to top |
|
 |
Baxsan Member
Joined: 01 May 2007 Posts: 9
|
Posted: 08/05/07 08:04 Post subject: |
|
|
| How can I do that?
|
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 08/05/07 12:56 Post subject: |
|
|
Using the Position property.
Please read the ReadMe file.
_________________ Kambiz
 |
|
| Back to top |
|
 |
|