使用savefiledialogue保存后,Wav文件无法打开 [英] Wav file not opening after saving it using savefiledialogue

查看:113
本文介绍了使用savefiledialogue保存后,Wav文件无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm supposed to explore ways to record audio files and save it in vb.net. One of the methods i found is using "winmm.dll", the code works fine, the sound is recorded as it should be and previewed, but after saving it through SaveFileDialogue and opening it, i get the message "can't render file" or "unsupported file format" or "corrupted" on my Mediaplayers applications.

The files saved as .wav.

Is it a directory error or what?





我尝试过:



公共类SoundRecorder

Dim soundrecord As Object

私有声明函数mciSendString Libwinmm.dll别名mciSendStringA(ByVal lpstrCommand As String,ByVal lpstrReturnString As String,ByVal uReturnLength As Integer,ByVal hwndCallback As Integer)As Integer

Private Sub SoundRecorder_Load(ByVal sender As System.Object,ByVal e As System .EventArgs)处理MyBase.Load



End Sub

Private Sub button6_Click(ByVal sender As System.Object,ByVal e As System.EventArgs )处理Button6.Click

Me.Dispose()

End Sub



Private Sub button1_Click(ByVal sender) As System.Object,ByVal e As System.EventArgs)处理Button1.Click

button1.Enabled = False

button2.Enabled = True

mciSendString(打开新类型waveaudio Alias recsound,,0,0)

mciSendString(record recsound,,0,0)

Label1。 Text =Recording ...

Label1.Visible = True

End Sub



Private Sub button2_Click (ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button2.Click

button1.Enabled = True

button2.Enabled = False

button3.Enabled = True

mciSendString(save recsound soundrecord,,0,0)

mciSendString(close recsound,,0 ,0)

Label1.Text =已停止......

Label1.Visible = False

My.Computer.Audio.Stop( )

End Sub



Private Sub button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button3.Click

button1.Enabled = False

button2.Ena bled = False

button3.Enabled = False

button4.Enabled = True

Label1.Text =正在播放......

Label1.Visible = True

My.Computer.Audio.Play(soundrecord,AudioPlayMode.Background)

End Sub



Private Sub button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button4.Click

My.Computer.Audio.Stop()

button1.Enabled = True

button2.Enabled = False

button3.Enabled = False

button4.Enabled =错误

Label1.Text =已停止

Label1.Visible = False

结束次级



Private Sub button5_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button5.Click

Dim saveFileDialog1 As New SaveFileDialog

Dim mystream作为Stream

saveFileDialog1.Filter =wav files(* .wav)| * .wav |所有文件(*。*)| *。*

saveFileDialog1.FilterIndex = 2

saveFileDialog1.RestoreDirectory = True



如果saveFileDialog1.ShowDialog()= DialogResult.OK那么

mystream = saveFileDialog1.OpenFile()

mystream.Equals(soundrecord)

mystream.close()

Label1.Text =已保存

Label1.Visible = False

结束如果





End Sub

End Class



What I have tried:

Public Class SoundRecorder
Dim soundrecord As Object
Private Declare Function mciSendString 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 SoundRecorder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Me.Dispose()
End Sub

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
button1.Enabled = False
button2.Enabled = True
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
Label1.Text = "Recording..."
Label1.Visible = True
End Sub

Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
button1.Enabled = True
button2.Enabled = False
button3.Enabled = True
mciSendString("save recsound soundrecord", "", 0, 0)
mciSendString("close recsound", "", 0, 0)
Label1.Text = "Stopped..."
Label1.Visible = False
My.Computer.Audio.Stop()
End Sub

Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
button1.Enabled = False
button2.Enabled = False
button3.Enabled = False
button4.Enabled = True
Label1.Text = "Playing..."
Label1.Visible = True
My.Computer.Audio.Play("soundrecord", AudioPlayMode.Background)
End Sub

Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
My.Computer.Audio.Stop()
button1.Enabled = True
button2.Enabled = False
button3.Enabled = False
button4.Enabled = False
Label1.Text = "Stopped"
Label1.Visible = False
End Sub

Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim saveFileDialog1 As New SaveFileDialog
Dim mystream As Stream
saveFileDialog1.Filter = "wav files (*.wav)|*.wav|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True

If saveFileDialog1.ShowDialog() = DialogResult.OK Then
mystream = saveFileDialog1.OpenFile()
mystream.Equals(soundrecord)
mystream.close()
Label1.Text = "Saved"
Label1.Visible = False
End If


End Sub
End Class

推荐答案

mystream.Equals(soundrecord)
mystream.close()



将流数据写入文件的代码在哪里?


Where is the code that writes the stream data to the file?


这篇关于使用savefiledialogue保存后,Wav文件无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆