您没有指定用于播放 MP3 的内容。但我正在使用BASS。您的问题是在他们的论坛中提出的。在这里。顺便说一句,您可能需要BASS .NET(它是 BASS 的 .NET 包装器)才能将 BASS 与 C# 一起使用。
由于有问题的变化而编辑:
您可以在我上面给出的链接中使用 bass.dll。下载 .NET 包装器,将其添加到您的引用中。这是VB 6中的一个示例。只需将longs更改为整数,将整数更改为shorts,函数名称相同。你应该从这里得到这个想法。
Public Sub GetSilenceLength(ByVal file As String, ByVal threshold As Long, ByRef startp As Long, ByRef endp As Long)
Dim buf(50000) As Integer
Dim count As Long, pos As Long
Dim chan As Long
Dim a As Long, b As Long
Dim c As Long, d As Long
count = 0
chan = BASS_StreamCreateFile(BASSFALSE, file, 0, 0, BASS_STREAM_DECODE) 'create decoding channel
If (chan = 0) Then Exit Sub
Do
b = BASS_ChannelGetData(chan, buf(0), 20000) 'decode some data
b = b / 2 'bytes -> samples
a = 0
Do 'count silent samples
a = a + 1
Loop While ((a < b) And (Abs(buf(a)) <= threshold))
count = count + (a * 2)
If (a < b) Then 'sound has bagun
'move back to a quieter sample (to avoid "click")
Do
a = a - 1
count = count - 2
Loop While ((a) And (Abs(buf(a)) > threshold / 4))
Exit Do
End If
Loop While (BASS_ChannelIsActive(chan))
startp = count
pos = BASS_StreamGetLength(chan)
Do
pos = IIf(pos < 100000, 0, pos - 100000) 'step back a bit
BASS_ChannelSetPosition chan, pos
d = BASS_ChannelGetData(chan, buf(0), 100000) ' decode some data
d = d / 2 'bytes -> samples
c = d
Do
c = c - 1 'count silent samples
Loop While (c > 0) And (Abs(buf(c)) <= threshold / 2) 'Here is the correction
If (c > 0) Then 'sound has begun
count = pos + c * 2
Exit Do
End If
Loop While (pos > count)
endp = count
BASS_StreamFree (chan)
End Sub
此外,如果你想褪色,那是另一个简单的故事。