English 中文(简体)
串流读读返回长度 0, 而流流是打开的, 且在流中有有效数据
原标题:Stream read return length 0 while stream is open and has valid data in it

我有一个小问题:在VS2010年的“WinForm App”中, 我试图做Alvas.Audio似乎可行的工作。见(c#ex:http://alvas.net/alvas.audio.tips.aspx#tip94

 Dim data() As Byte = wr.ReadData(second * i, second)

结果给了我 data. long ()=0 。 我没有任何例外, 我可以读取它的格式, 无论我使用什么读者, 我都有这个问题 。

EDIT : 经过一些测试后, 第一步我创建的未压缩文件( 以PCM格式, 有. wav 扩展) 似乎无法被 Alvas. audio 库确认为第二步 。 我必须忽略音频文件标记或类似的东西 。

以下是可能来源的代码(基本上这是第1步):

    Dim functOut As String = String.Empty
    Dim wr As Alvas.Audio.IAudioReader = Nothing
    Dim fs As IO.FileStream = Nothing
    Dim i As Integer = 0
    Dim tmpData() As Byte = Nothing
    Dim dataPCM() As Byte = Nothing
    Dim newFormat As IntPtr = IntPtr.Zero
    Try
        Select Case IO.Path.GetExtension(filename).ToLower()
            Case ".wav"
                wr = New Alvas.Audio.WaveReader(IO.File.OpenRead(filename))
                filename = IO.Path.GetTempPath & IO.Path.GetFileNameWithoutExtension(filename) & "2" & IO.Path.GetExtension(filename)
            Case ".mp3"
                wr = New Alvas.Audio.Mp3Reader(IO.File.OpenRead(filename))
            Case Else : wr = New Alvas.Audio.DsReader(filename)
        End Select

        functOut = IO.Path.ChangeExtension(filename, ".wav")

        Dim format As IntPtr = wr.ReadFormat()
        Dim formatDetail As Alvas.Audio.WaveFormat = Alvas.Audio.AudioCompressionManager.GetWaveFormat(format)


        If formatDetail.wFormatTag = Alvas.Audio.AudioCompressionManager.MpegLayer3FormatTag Then
            Alvas.Audio.AudioCompressionManager.Mp3ToWav(filename, functOut)
            Return True
        Else
            IO.File.Create(functOut).Close()
            While True
                tmpData = wr.ReadData(SECONDS * i, SECONDS)
                If tmpData Is Nothing Or tmpData.Length = 0 Then Exit While

                If formatDetail.wBitsPerSample < 16 Then
                    Alvas.Audio.AudioCompressionManager.ToPcm16Bit(format, tmpData, newFormat, dataPCM)
                Else 
                    newFormat = format
                    dataPCM = tmpData
                End If

                formatDetail = Alvas.Audio.AudioCompressionManager.GetWaveFormat(newFormat)

                fs = IO.File.Open(filename, IO.FileMode.Append, IO.FileAccess.Write)
                Using ww As New Alvas.Audio.WaveWriter(fs, Alvas.Audio.AudioCompressionManager.FormatBytes(newFormat))
                    ww.Write(dataPCM, 0, dataPCM.Length())
                End Using

                i += 1
                tmpData = Nothing
            End While
            Return True
        End If

        wr.Close()
    Catch ex As Exception
        filename = String.Empty
        Throw ex
    Finally
        fs.Close()
        wr.Close()
        filename = functOut
        GC.Collect()
    End Try

我如何写出结果流以确保我稍后能再读一遍?

任何想法都将受到高度赞赏。

最佳回答

我找到解决办法了

PCM 文件是无标题的。 所以保存时, 即使有波文字和线 Alvas.Audio.Audio.AudioCompressionManager.formatBytes(新Format) 也被忽略 。

可以做两件事:

  • 查找可识别无页眉文件并允许读取文件的读者 。

  • 将文件解码到PCM 文件中并将其编码到新格式(例如.mp3),而不将结果文件写入文件系统(要好得多)

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签