0
我正在製作一個錄製音頻的程序。My.Computer.Audio.Play上的FileNotFoundException異常
代碼:在線My.Computer.Audio.Play("c:\mic.wav", AudioPlayMode.Background)
發生
Imports System.Runtime.InteropServices
Public Class Form1
Private Declare Function record Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
record("open new Type waveaudio Alias recon", "", 0, 0)
record("record recon", "", 0, 0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
record("save recon c:\mic.wav", "", 0, 0)
record("close recon", "", 0, 0)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.Audio.Play("c:\mic.wav", AudioPlayMode.Background)
End Sub
End Class
錯誤:
FileNotFoundException異常是未處理 請務必聲音文件存在於指定的位置。
是否在文件存在C:\ mic.wav – Bugs
不,我互聯網上閱讀,因爲該代碼自動創建mic.wav然後播放它 –
這是上個世紀的代碼。就像它一樣,C:\目錄受UAC保護。所以Button2將不起作用,因爲您忽略了mciSendString()的返回值,所以無法找到。 Button3因此註定要失敗。選擇一個更好的目錄和一個[正確的聲明](http://pinvoke.net/default.aspx/winmm/mciSendString.html)並添加* required *錯誤報告。 –