注册 登录
编程论坛 VB.NET论坛

怎样读取MPG文件的媒体信息?读取WAV文件的媒体信息我有了。

g12339645 发布于 2012-06-21 19:47, 818 次点击
RT
程序代码:
Private Sub getWavData(ByVal s As String)
        Try
            Dim MyFile As String = s
            Dim MyFileInfo As New (MyFile)
            Dim MyStream As = MyFileInfo.OpenRead()
            Dim MyInfo As String = MyFile + "文件的标志信息如下:" + vbCrLf
            If (MyStream.Length >= 44) Then
                Dim MyBytes(44) As Byte
                MyStream.Read(MyBytes, 0, 44)
                System.Text.Encoding.Default.GetString(MyBytes, 0, 4)
                If ((System.Text.Encoding.Default.GetString(MyBytes, 0, 4) = "RIFF") And _
                    (System.Text.Encoding.Default.GetString(MyBytes, 8, 4) = "WAVE") And _
                    (System.Text.Encoding.Default.GetString(MyBytes, 12, 4) = "fmt ")) Then
                    MyInfo += vbCrLf + " GroupID:" + _
                            System.Text.Encoding.Default.GetString(MyBytes, 0, 4).ToString()
                    System.BitConverter.ToInt32(MyBytes, 4)
                    MyInfo += vbCrLf + " FileSize:" + _
                                        System.BitConverter.ToInt32(MyBytes, 4).ToString()
                    MyInfo += vbCrLf + " RiffType:" + _
                            System.Text.Encoding.Default.GetString(MyBytes, 8, 4).ToString()
                    MyInfo += vbCrLf + " ChunkID:" + _
                            System.Text.Encoding.Default.GetString(MyBytes, 12, 4).ToString()
                    MyInfo += vbCrLf + " ChunkSize:" + _
                                        System.BitConverter.ToInt32(MyBytes, 16).ToString()
                    MyInfo += vbCrLf + " WFormatTag:" + _
                                        System.BitConverter.ToInt16(MyBytes, 20).ToString()
                    MyInfo += vbCrLf + " WChannels:" + _
                                        System.BitConverter.ToUInt16(MyBytes, 22).ToString()
                    MyInfo += vbCrLf + " DWSamplesPerSec:" + _
                                        System.BitConverter.ToUInt32(MyBytes, 24).ToString()
                    MyInfo += vbCrLf + " DWavBytesPerSec:" + _
                                        System.BitConverter.ToUInt32(MyBytes, 28).ToString()
                    MyInfo += vbCrLf + " WBLockAlign:" + _
                                        System.BitConverter.ToUInt16(MyBytes, 32).ToString()
                    MyInfo += vbCrLf + " WBitsPerSample:" + _
                                        System.BitConverter.ToUInt16(MyBytes, 34).ToString()
                    MyInfo += vbCrLf + " DataChunkID:" + _
                            System.Text.Encoding.Default.GetString(MyBytes, 36, 4).ToString()
                    MyInfo += vbCrLf + " DataSize:" + _
                                            System.BitConverter.ToInt32(MyBytes, 40).ToString()
                End If
            End If
            MyStream.Close()
            MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

0 回复
1