获取 wav 音频的长度(以分钟/秒为单位)
使用 DelphiXE,我试图在标签上显示 wav 文件的长度。这是加载到 tMediaPlayer 中的固定比特率 64kbps 的 wav 文件。
之前关于该任务的 SO 帖子位于此处。但没有显示任何代码,并且 Devhood 的链接似乎不再有效,因此我无法尝试该方法。
我还尝试了 HERE 中的代码,但它给出了错误结果如下。
type
HMSRec = record
Hours: byte;
Minutes: byte;
Seconds: byte;
NotUsed: byte;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TheLength: LongInt;
begin
{ Set time format - note that some devices don’t support tfHMS }
MediaPlayer1.TimeFormat := tfHMS;
{ Store length of currently loaded media }
TheLength := MediaPlayer1.Length;
with HMSRec(TheLength) do { Typecast TheLength as a HMSRec record }
begin
Label1.Caption := IntToStr(Hours); { Display Hours in Label1 }
Label2.Caption := IntToStr(Minutes); { Display Minutes in Label2 }
Label3.Caption := IntToStr(Seconds); { Display Seconds in Label3 }
end;
end;
此代码给出的值为 24:23:4,而它应该是 0:04:28。
该代码是否存在明显的问题,或者是否有一些更优雅的方法来完成此任务?
一如既往,感谢您的帮助。
Using DelphiXE, I'm trying to show the length of a wav file on a label. This is a wav file at fixed bit rate of 64kbps that is loaded into a tMediaPlayer.
A previous SO post on the task is HERE. But no code is shown and the link to Devhood no longer appears to work so I was unable to try that method.
I also tried the code from HERE but it gives incorrect results as follows.
type
HMSRec = record
Hours: byte;
Minutes: byte;
Seconds: byte;
NotUsed: byte;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TheLength: LongInt;
begin
{ Set time format - note that some devices don’t support tfHMS }
MediaPlayer1.TimeFormat := tfHMS;
{ Store length of currently loaded media }
TheLength := MediaPlayer1.Length;
with HMSRec(TheLength) do { Typecast TheLength as a HMSRec record }
begin
Label1.Caption := IntToStr(Hours); { Display Hours in Label1 }
Label2.Caption := IntToStr(Minutes); { Display Minutes in Label2 }
Label3.Caption := IntToStr(Seconds); { Display Seconds in Label3 }
end;
end;
This code gives a value of 24:23:4, when it should be 0:04:28.
Is there an obvious problem with that code, or is there some more elegant way to accomplish this?
As always, thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不做一些简单的小学数学呢?
但为什么HMS不起作用呢?好吧,根据官方文档:
Why not just do some simple elementary-school math?
But why don't HMS work? Well, according to the official documentation: