M microbit Unregistered / Unconfirmed GUEST, unregistred user! 2001-10-13 #1 有什么样的方法精确确定wav文件的播放时间长度?
T tbs1999 Unregistered / Unconfirmed GUEST, unregistred user! 2001-10-13 #2 你可以使用一个TIMER控件,把它的Interval设置为1,也就是一毫秒,再用一个 MediaPlayer控件来播放这个WAV文件,使用一个全局变量在onTimer事件来累加, 播完了后,ShowMessage这个全局变量的值。
你可以使用一个TIMER控件,把它的Interval设置为1,也就是一毫秒,再用一个 MediaPlayer控件来播放这个WAV文件,使用一个全局变量在onTimer事件来累加, 播完了后,ShowMessage这个全局变量的值。
D delphibyte Unregistered / Unconfirmed GUEST, unregistred user! 2001-10-13 #4 嗯, 有, 就是计算wav的时间长度啊, 每个wav文件都有一个头部, 在这个头部里 包含了声音的质量, 即采样频率, 如44100Hz啦, 而每次取样的位数也是在这个头部 里记录, 例如16位(2字节), 然后是单声道还是双声道 例如CD音质的wav, 它一秒钟的长度就是44100*2(16位)*2(双声道)=176400字节 你只要理解它的存储结构, 可以计算出精确的时间. Wav文件的头部数据结构在很多 有关wav的构件代码中都有定义.
嗯, 有, 就是计算wav的时间长度啊, 每个wav文件都有一个头部, 在这个头部里 包含了声音的质量, 即采样频率, 如44100Hz啦, 而每次取样的位数也是在这个头部 里记录, 例如16位(2字节), 然后是单声道还是双声道 例如CD音质的wav, 它一秒钟的长度就是44100*2(16位)*2(双声道)=176400字节 你只要理解它的存储结构, 可以计算出精确的时间. Wav文件的头部数据结构在很多 有关wav的构件代码中都有定义.
L LeeChange Unregistered / Unconfirmed GUEST, unregistred user! 2001-10-15 #5 用MediaPlayer控件打开,读Length属性
C copy_paste Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-25 #6 //返回秒数 function ReadWaveTime(FileName: string): Integer; type TWaveFileHeader = packed record FType: Integer; Size: Longint; RType: Integer; end; TWaveChunkHeader = packed record CType: Longint; Size: Longint; end; const ID_RIFF = Ord('R') + Ord('I') * $100 + Ord('F') * $10000 + Ord('F') * $1000000; ID_WAVE = Ord('W') + Ord('A') * $100 + Ord('V') * $10000 + Ord('E') * $1000000; ID_FMT = Ord('f') + Ord('m') * $100 + Ord('t') * $10000 + Ord(' ') * $1000000; ID_FACT = Ord('f') + Ord('a') * $100 + Ord('c') * $10000 + Ord('t') * $1000000; ID_DATA = Ord('d') + Ord('a') * $100 + Ord('t') * $10000 + Ord('a') * $1000000; var DataSize: Integer; Format: TWaveFormatEx; Stream: TFileStream; Header: TWaveFileHeader; Chunk: TWaveChunkHeader; begin Result := 0; DataSize := 0; FilLChar(Format, SizeOf(Format), 0); Stream := TFileStream.Create(FileName, fmOpenRead); with Streamdo try ReadBuffer(Header, Sizeof(Header)); if (Header.FType <> ID_RIFF) and (Header.RType <> ID_WAVE) then raise Exception.Create('invalid wave file format'); Stream.ReadBuffer(Chunk, Sizeof(Chunk)); while Chunk.CType <> 0do begin if Chunk.CType = ID_FMT then Stream.ReadBuffer(Format, Chunk.Size) else if Chunk.CType = ID_DATA then begin DataSize := Stream.Size - Stream.Position; break; end else if Chunk.CType = ID_FACT then Stream.Seek(Chunk.Size, soFromCurrent); FillChar(Chunk, SizeOf(Chunk), 0); Stream.ReadBuffer(Chunk, Sizeof(Chunk)); end; if (DataSize <> 0) and (Format.nAvgBytesPerSec <> 0) then Result := DataSize div Format.nAvgBytesPerSec; finally Free; end; end; TWaveFormatEx : nAvgBytesPerSec: 声音文件中声音频率每秒钟产生出的字节数
//返回秒数 function ReadWaveTime(FileName: string): Integer; type TWaveFileHeader = packed record FType: Integer; Size: Longint; RType: Integer; end; TWaveChunkHeader = packed record CType: Longint; Size: Longint; end; const ID_RIFF = Ord('R') + Ord('I') * $100 + Ord('F') * $10000 + Ord('F') * $1000000; ID_WAVE = Ord('W') + Ord('A') * $100 + Ord('V') * $10000 + Ord('E') * $1000000; ID_FMT = Ord('f') + Ord('m') * $100 + Ord('t') * $10000 + Ord(' ') * $1000000; ID_FACT = Ord('f') + Ord('a') * $100 + Ord('c') * $10000 + Ord('t') * $1000000; ID_DATA = Ord('d') + Ord('a') * $100 + Ord('t') * $10000 + Ord('a') * $1000000; var DataSize: Integer; Format: TWaveFormatEx; Stream: TFileStream; Header: TWaveFileHeader; Chunk: TWaveChunkHeader; begin Result := 0; DataSize := 0; FilLChar(Format, SizeOf(Format), 0); Stream := TFileStream.Create(FileName, fmOpenRead); with Streamdo try ReadBuffer(Header, Sizeof(Header)); if (Header.FType <> ID_RIFF) and (Header.RType <> ID_WAVE) then raise Exception.Create('invalid wave file format'); Stream.ReadBuffer(Chunk, Sizeof(Chunk)); while Chunk.CType <> 0do begin if Chunk.CType = ID_FMT then Stream.ReadBuffer(Format, Chunk.Size) else if Chunk.CType = ID_DATA then begin DataSize := Stream.Size - Stream.Position; break; end else if Chunk.CType = ID_FACT then Stream.Seek(Chunk.Size, soFromCurrent); FillChar(Chunk, SizeOf(Chunk), 0); Stream.ReadBuffer(Chunk, Sizeof(Chunk)); end; if (DataSize <> 0) and (Format.nAvgBytesPerSec <> 0) then Result := DataSize div Format.nAvgBytesPerSec; finally Free; end; end; TWaveFormatEx : nAvgBytesPerSec: 声音文件中声音频率每秒钟产生出的字节数
N net_donkey Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-25 #7 delphibyte go on please!
B BreathSky Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-26 #8 wav默认的播放模式是以毫秒播放的 取得MEDIAPLAYER.LENGTH/1000即可单位是秒
D D影子D Unregistered / Unconfirmed GUEST, unregistred user! 2002-04-01 #9 buttonclick1() begin mediaplayer1.filename:='c:/12.wav'; mediaplayer1.open; mediaplayer1.play; button1.caption:=timetostr(time()); end; procedure TForm1.MediaPlayer1Notify(Sender: TObject); begin button1.caption:=timetostr(time()); end; 两个时间相减 或者 用mediaplayer打开wav文件 时间长度:mediaplayer1.length 单位/毫秒
buttonclick1() begin mediaplayer1.filename:='c:/12.wav'; mediaplayer1.open; mediaplayer1.play; button1.caption:=timetostr(time()); end; procedure TForm1.MediaPlayer1Notify(Sender: TObject); begin button1.caption:=timetostr(time()); end; 两个时间相减 或者 用mediaplayer打开wav文件 时间长度:mediaplayer1.length 单位/毫秒