(这是this one的后续问题。)
我想异步读取无限的音频流,以便我可以对获得的数据进行JIT分析。使用WebClient
对象的DownloadDataAsync
方法,我可以轻松启动下载,请参阅以下Win表单项目:
Imports System.Net 'For WebClient
Public Class Form1
Private WithEvents c As New WebClient()
Protected Overrides Sub Finalize()
c.Dispose()
MyBase.Finalize()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim u As New Uri("http://flower.serverhostingcenter.com:8433/;")
c.DownloadDataAsync(u)
End Sub
Private Sub c_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles c.DownloadProgressChanged
Debug.Print(e.BytesReceived.ToString & " B received.")
End Sub
End Class
,根据DownloadProgressChanged
事件输出到即时窗口,流似乎正在流动:
2920 B received.
48180 B received.
56940 B received.
61320 B received.
87600 B received.
94900 B received.
160436 B received.
162060 B received.
227596 B received.
...
但是,我找不到一种方法来读取获得的数据。由于这是一个源源不断的流,DownloadDataCompleted
永远不会发射(除了使用的事件之外,任何其他事件也不会发射)。
如何访问获取的数据?
答案 0 :(得分:2)
将OpenReadAsync
与OpenReadCompleted
事件结合使用。
Private Sub c_OpenReadCompleted(sender As Object, e As OpenReadCompletedEventArgs) Handles c.OpenReadCompleted
Dim stream = e.Result
End Sub