Fails playing a WAV file - vb.net

I read some tutorials on how to play a WAV file in VB.Net using the mciSendString() function. For some reason, it succeeds in recording and saving the sound into a file (I listened to the file with a sound application), but plays nothing and triggers no error.
Here's the code:
'Start recording
If OvalShape1.FillColor = Color.DarkRed Then
OvalShape1.FillColor = Color.Red
Try
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
OvalShape1.FillColor = Color.DarkRed
End Try
'Stop recording
Else
OvalShape1.FillColor = Color.DarkRed
Try
'generate unique filename and save as tmp file
Dim TempFullFileName As String = IO.Path.GetTempFileName()
'save recording
mciSendString("save recsound " & Chr(34) & TempFullFileName & Chr(34), "", 0, 0)
mciSendString("close recsound", "", 0, 0)
mciSendString("open " & Chr(34) & TempFullFileName & Chr(34) & " Alias recsound", "", 0, 0)
mciSendString("play recsound", Nothing, 0, 0)
mciSendString("close recsound", "", 0, 0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
OvalShape1.FillColor = Color.DarkRed
End Try
End If
Originally, I simply saved and played the file, next I closed/reopened the sound file but it makes no difference. Am I missing something?
Thank you.
Edit:
Try/catch doesn't display errors returned by mciSendString -> Use mciGetErrorString() to check the returned value
To play the whole sound file, you must add "wait" before closing
Here's some working code:
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
Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer
Private Function GetMCIErrorString(ByVal ErrorCode As Integer) As String
GetMCIErrorString = Space(1024)
mciGetErrorString(ErrorCode, GetMCIErrorString, Len(GetMCIErrorString))
GetMCIErrorString = Trim(GetMCIErrorString)
End Function
Private Sub Form1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
Dim SoundFile As String = "C:\Documents and Settings\joe\Local Settings\Temp\tmp8FED.wav"
SoundFile = ControlChars.Quote & SoundFile & ControlChars.Quote
Dim StringToOpen As String = "open " & DummyFile & " alias recsound"
ErrCode = mciSendString(StringToOpen, "", 0, 0)
If ErrCode <> 0 Then
MessageBox.Show(GetMCIErrorString(ErrCode))
Exit Sub
End If
ErrCode = mciSendString("play recsound wait", Nothing, 0, 0)
If ErrCode <> 0 Then
MessageBox.Show(GetMCIErrorString(ErrCode))
Exit Sub
End If
ErrCode = mciSendString("close recsound", "", 0, 0)
If ErrCode <> 0 Then
MessageBox.Show(GetMCIErrorString(ErrCode))
Exit Sub
End If
End Sub

Related

Save pictures while I scrape them from website using VB.NET

I find a code on YouTube when I use it on my visual basic and debug it and find pictures but when i want to save them software gives me this message here.
Private Sub btnSaveImages_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnSaveImages.Click
Dim dir_name As String = txtDirectory.Text
If Not dir_name.EndsWith("\") Then dir_name &= "\"
For Each pic As PictureBox In flpPictures.Controls
Dim bm As Bitmap = pic.Image
Dim filename As String = pic.Tag
filename = _
filename.Substring(filename.LastIndexOf("/") + _
1)
Dim ext As String = _
filename.Substring(filename.LastIndexOf("."))
Dim full_name As String = dir_name & filename
Select Case ext
Case ".bmp"
bm.Save(full_name, Imaging.ImageFormat.Bmp)
Case ".gif"
bm.Save(full_name, Imaging.ImageFormat.Gif)
Case ".jpg", "jpeg"
bm.Save(full_name, Imaging.ImageFormat.Jpeg)
Case ".png"
bm.Save(full_name, Imaging.ImageFormat.Png)
Case ".tiff"
bm.Save(full_name, Imaging.ImageFormat.Tiff)
Case Else
MessageBox.Show( _
"Unknown file type " & ext & _
" in file " & filename, _
"Unknown File Type", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Select
Next pic
Beep()
End Sub
The issue is that LastIndexOf isn't finding . in your filename. This then passes -1 to to SubString which throws the error you're seeing.
Instead of writing the file parsing yourself use the methods of System.Io.Path such as
System.IO.Path.GetDirectoryName(filename)
System.IO.Path.GetFileName(filename)
System.IO.Path.GetFileNameWithoutExtension(filename)
Private Sub btnSaveImages_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnSaveImages.Click
For Each pic As PictureBox In flpPictures.Controls
Dim bm As Bitmap = pic.Image
Dim path As String = pic.Tag
Dim filename = IO.Path.GetFileName(path)
Dim ext = IO.Path.GetExtension(path)
Dim full_name = IO.Path.Combine(txtDirectory.txt, filename)
....

How can I play my all videos with my specific folder with MCISendString?

I need a way to make my all video files that I saved with my specific folder play and loop again the videos after play.
I already have some code from the basic tutorials of MCISendstring over the internet, but only one video is playing with my folder path I think something wrong with my code. Any help would be greatly appreciated.
So far this is my code:
Public Class Form1
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
Dim filename As String = "D:\Movielist\*.*"
Dim filename As String = "D:\Movielist\Cronos.wmv"
Dim retVal As Integer
Dim playing As Boolean = False
Private Sub Panel1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.SizeChanged
If playing Then
SizeVideoWindow(Panel1.Size)
End If
End Sub
Private Sub SizeVideoWindow(ByVal maxSize As Size)
Dim ActualMovieSize As Size = getDefaultSize()
Dim AspectRatio As Single = CSng(ActualMovieSize.Width / ActualMovieSize.Height)
Dim iLeft As Integer = 0
Dim iTop As Integer = 0
Dim newWidth As Integer = maxSize.width
Dim newHeight As Integer = CInt(newWidth \ AspectRatio)
If newHeight > maxSize.height Then
newHeight = maxSize.height
newWidth = CInt(newHeight * AspectRatio)
iLeft = (maxSize.Width - newWidth) \ 2
Else
iTop = (maxSize.Height - newHeight) \ 2
End If
mciSendString("put movie window at " & iLeft & " " & iTop & " " & newWidth & " " & newHeight, "", 0, 0)
mciSendString("play movie repeat", "", 0, 0)
Console.ReadLine()
End Sub
Public Function getDefaultSize() As Size
Dim c_Data As String = Space(128)
mciSendString("where movie source", c_Data, 128, 0)
Dim parts() As String = Split(c_Data, " ")
Return New Size(CInt(parts(2)), CInt(parts(3)))
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
filename = Chr(34) & filename & Chr(34)
retVal = mciSendString("open " & filename & " type mpegvideo alias movie parent " _
& Panel1.Handle.ToInt32 & " style child", "", 0, 0)
retVal = mciSendString("play movie", "", 0, 0)
playing = True
SizeVideoWindow(Panel1.Size)
End Sub
End Class

Saving Audio File on SQL Server Management Studio using VB.net 2010

Please help me with this audio file saving on SQL server management studio connection.
I have a recorder on vb.net 2010 and i want to save my audio recorded in SQL and display it on DataGridview (vb.net 2010) at the same time save it on my database which is SQL.
Please help me guys, what are the propably codes for this saving thing on database. Please do not use C# and C++ as a guide or source code. Only VB.net
Create an Access Database in your D: drive and name it SoundDB.accdb
Create a table in the DB and name it tblSounds with 3 fields sndid text(2), sndname text(20) , sndbinary OLEObject)
Create a new form in your project
Add a Textbox and 3 buttons.
Type an Id number (2 digits) in the textbox
button 1 will start recording
button2 will stop recording and save the sound to your DB
button3 will fetch from DB the sound for the ID you specify in the textbox and play it
Add these lines to the beginning of your code.
Imports System.IO
Imports System.Text
Imports System.Data.OleDb
Add this declaration to your code
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As StringBuilder, _
ByVal uReturnLength As Integer, _
ByVal hwndCallback As IntPtr) As Integer
Paste the Sub routines below into your code
Private Sub SaveSndtoDB(ByVal SndID As String, ByVal sndName As String)
Dim Connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\SoundDB.accdb")
Dim SndSourceStream As Stream = New FileStream("D:\FileName.wav", FileMode.Open, FileAccess.Read)
Dim BinarySndReader As New BinaryReader(SndSourceStream)
Dim bytes As Byte() = BinarySndReader.ReadBytes(SndSourceStream.Length)
Connection.Open()
'insert the file into database
Dim cmd As New OleDb.OleDbCommand("INSERT INTO tblSounds (sndid,sndname,sndbinary) VALUES ('" + SndID + "','" + sndName + "',#SndBinary)", Connection)
cmd.Parameters.AddWithValue("#SoundBinary", bytes)
Try
cmd.ExecuteNonQuery()
MsgBox("File Uploaded Successfully")
Catch ex As Exception
MsgBox("There was a problem, file upload was not successful. " + ex.Message)
End Try
SndSourceStream.Flush()
SndSourceStream.Close()
FileClose()
Reset()
Application.DoEvents()
End Sub
Private Sub PlaySndfromDB(ByVal sndID As String)
FileClose()
Reset()
Dim Connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\SoundDB.accdb")
Dim SndSourceStream As Stream = New FileStream("D:\FileName.wav", FileMode.Create, FileAccess.Write)
Try
Connection.Open()
Dim command As New OleDbCommand("SELECT sndbinary FROM tblsounds WHERE sndID = #ID", Connection)
command.Parameters.AddWithValue("#ID", sndID)
Dim soundData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
Connection.Close()
command.Dispose()
SndSourceStream.Write(soundData, 0, soundData.Length)
SndSourceStream.Flush()
SndSourceStream.Close()
My.Computer.Audio.Play("d:\FileName.wav", AudioPlayMode.Background)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub StartRecording()
mciSendString("open new type waveaudio alias mywav", Nothing, 0, 0)
mciSendString("record mywav", Nothing, 0, 0)
End Sub
Private Sub SaveRecording()
mciSendString("stop mywav", Nothing, 0, 0)
mciSendString("save mywav d:\FileName.wav", Nothing, 0, 0)
mciSendString("close mywav", Nothing, 0, 0)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
StartRecording()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveRecording()
Application.DoEvents()
SaveSndtoDB(TextBox1.Text, "Snd" + TextBox1.Text)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PlaySndfromDB(TextBox1.Text)
End Sub
================================================================================
Hope this helps, feel free to let me know if you need further help.
I have not tested this code with very long sound files, it works well with snippets.
'create a table in SQL with feilds name F1,F2,F3 .... and Aud as image
Dim path
path = "Data Source=SERVER\SQLEXPRESS;Initial Catalog="DatabaseName";Integrated Security=True; " ';user=Uni;password=uni"
Con.Open()
Public Sub InsertAudioDataInTable(TableName, TableMapingName, LoopStart, LoopEnd, TaxtName, Panel, AdioPath)
Dim SndSourceStream As Stream = New FileStream(AdioPath, FileMode.Open, FileAccess.Read)
Dim BinarySndReader As New BinaryReader(SndSourceStream)
Dim arrImage As Byte() = BinarySndReader.ReadBytes(SndSourceStream.Length)
Dim strImage As String
strImage = "#Aud"
Dim b = 0
Dim dataContaner(LoopEnd + 2 - LoopStart) As String
For a = LoopStart To LoopEnd
dataContaner(b) = Panel.Controls(TaxtName & a).Text.ToString
b = b + 1
Next
''''''''''''''
Dim myCmd As New SqlCommand
myCmd.Connection = Con
''''''''''
Dim T As String
' T.Text = null
Dim aaa = "INSERT INTO " & TableName
Dim bbb = ""
For i = LoopStart To LoopEnd
bbb = bbb + "F" & i & ","
Next
T = aaa & " (" + bbb & "Aud"
' T = T.Remove(T.Length - 1)
T = T & ")VALUES ("
Dim ccc = ""
b = 0
For a = LoopStart To LoopEnd
ccc = ccc & "'" & dataContaner(b) & "',"
b = b + 1
Next
T = T + ccc
myCmd.CommandText = T + strImage & ")"
myCmd.Parameters.Add(strImage, SqlDbType.Binary).Value = arrImage
myCmd.ExecuteNonQuery()
''''''''
End Sub

VB.Net playing mp3 at the same time

I've been wondering about this, I have tried multiple suggestions I have got from different sites. I have my code here but it's not working.
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 Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim fileName As String
FileName = Chr(34) & (Button1.Text) & Chr(34)
mciSendString("open " & FileName & " alias myDevice", Nothing, 0, 0)
mciSendString("play myDevice", Nothing, 0, 0)
FileName = Chr(34) & (Button2.Text) & Chr(34)
mciSendString("open " & FileName & " alias myDevice", Nothing, 0, 0)
mciSendString("play myDevice", Nothing, 0, 0)
This code only plays the first song and will not play the second one...I'm thinking of creating another function similar to the one above with different name but still no luck.
Private Declare Function mciSendString2 Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal _
uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Any idea? Or is it possible to play multiple mp3 at the same time?
Although I am dealing with a different issue myself, I came across this in my search and can tell you the reason it cannot play the 2 files at the same time is because your alias is the same for both.
This method has worked well for me only during development but most computers I installed on would crash when i would issue the open command via mcisendstring. I haven't figured out why. Here's my code. Maybe it will help someone and maybe someone can figure out what I'm doing wrong. I've had problems getting 32 bit apps to run from my 64 bit development machine.
Imports System.Runtime.InteropServices
Imports System.Text
Public Class MediaPlayerClass
<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
End Function
<DllImport("winmm.dll")> _
Private Shared Function mciGetErrorString(errCode As Integer, ByVal errMsg As StringBuilder, bufferSize As Integer) As Integer
End Function
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function GetShortPathName(ByVal longPath As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal ShortPath As System.Text.StringBuilder, _
<MarshalAs(Runtime.InteropServices.UnmanagedType.U4)> ByVal bufferSize As Integer) As Integer
End Function
Private _filename As String
Private _MediaAlias As String
Private _Length As TimeSpan
Private _err As Integer
Public Property PlaylistId As Integer = 0
Private _OriginalVolume As Integer = 1000
Function ShortPathName(ByVal Path As String) As String
Dim sb As New System.Text.StringBuilder(1024)
Dim tempVal As Integer = GetShortPathName(Path, sb, 1024)
If tempVal <> 0 Then
Dim Result As String = sb.ToString()
Return Result
Else
Throw New Exception("Failed to return a short path")
End If
End Function
Public Sub New(Filename As String, MediaAlias As String)
_filename = ShortPathName(Filename)
_MediaAlias = MediaAlias.Replace(" ", "_")
'_Length = GetLength()
Try
My.Application.Log.WriteEntry("MediaPlayerClass.New - calling MCI OPEN")
' here is where it crashes
_err = mciSendString("open """ & _filename & """ alias " & MediaAlias, Nothing, 0, 0)
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & GetLastErrorMessage())
End Try
End Sub
Public Sub NewMP3(Filename As String)
Me.StopIt()
Me.CloseIt()
_filename = Filename
Try
My.Application.Log.WriteEntry("MediaPlayerClass.NewMP3 - calling MCI OPEN ")
_err = mciSendString("open """ & Filename & """ alias " & _MediaAlias, Nothing, 0, 0)
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & GetLastErrorMessage())
End Try
End Sub
Public ReadOnly Property Length As TimeSpan
Get
Return _length
End Get
End Property
Private Function GetLength() As TimeSpan
Dim lengthBuf As New StringBuilder(32)
Try
My.Application.Log.WriteEntry("MediaPlayerClass.GetLength - calling MCI OPEN")
_err = mciSendString("open """ & _filename & """ type waveaudio alias " & _MediaAlias, Nothing, 0, 0)
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & GetLastErrorMessage())
End Try
' Get the duration of the music
Try
_err = mciSendString("status wave length", lengthBuf, lengthBuf.Capacity, 0)
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & GetLastErrorMessage())
End Try
'mciSendString("close wave", Nothing, 0, 0)
Dim len As Integer = Integer.TryParse(lengthBuf.ToString, len)
Dim ts As TimeSpan = TimeSpan.FromMilliseconds(len)
Return ts
End Function
Public Function PlayIt(Optional WaitUntilFinishedPlaying As Boolean = False) As Integer
Try
My.Application.Log.WriteEntry("MediaPlayerClass.PlayIt - calling MCI PLAY")
_err = mciSendString("play " & _MediaAlias, Nothing, 0, IntPtr.Zero)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
While WaitUntilFinishedPlaying
If IsPlaying() Then
Threading.Thread.Sleep(250)
Else
Exit While
End If
End While
Return _err
End Function
Public Function PauseIt() As Integer
_err = mciSendString("pause " & _MediaAlias, Nothing, 0, IntPtr.Zero)
Return _err
End Function
Public Function ResumeIt() As Integer
_err = mciSendString("resume " & _MediaAlias, Nothing, 0, IntPtr.Zero)
Return _err
End Function
Public Function StopIt() As Boolean
_err = mciSendString("stop " & _MediaAlias, Nothing, 0, IntPtr.Zero)
Return _err
End Function
Public Function CloseIt() As Boolean
_err = mciSendString("close " & _MediaAlias, Nothing, 0, IntPtr.Zero)
Return _err
End Function
Public Function IsPlaying() As Boolean
Dim returnData As New StringBuilder(128)
_err = mciSendString("status " & _MediaAlias & " mode", returnData, 128, IntPtr.Zero)
Return (returnData.Length = 7 AndAlso returnData.ToString.Substring(0, 7) = "playing")
End Function
Public Function SetVolume(vol As Integer) As Integer
_err = -1
If vol >= 0 And vol <= 1000 Then
_err = mciSendString("setaudio " & _MediaAlias & " volume to " & vol.ToString, Nothing, 0, IntPtr.Zero)
End If
Return _err
End Function
Public Sub FadeOutAndPause()
_OriginalVolume = GetVolume()
For x As Integer = 30 To 1 Step -1
Me.SetVolume(Int(x / 30 * _OriginalVolume))
Threading.Thread.Sleep(100)
Next
Me.PauseIt()
End Sub
Public Sub PlayAndFadeIn()
Me.PlayIt()
For x As Integer = 1 To 30 Step 1
Me.SetVolume(Int(x / 30 * _OriginalVolume))
Threading.Thread.Sleep(100)
Next
End Sub
Public Function GetVolume() As Integer
Dim returnData As New StringBuilder(128)
_err = mciSendString("status " & _MediaAlias & " volume", returnData, 128, IntPtr.Zero)
'MsgBox(returnData.ToString)
If _err = 0 Then
Return CInt(returnData.ToString)
Else
Return 1000
End If
End Function
Public Function SetBalance(bal As Integer) As Integer
If bal >= 0 AndAlso bal <= 1000 Then
_err = mciSendString("setaudio " & _MediaAlias & " left volume to " + (1000 - bal).ToString, Nothing, 0, IntPtr.Zero)
_err = mciSendString("setaudio " & _MediaAlias & " right volume to " + bal.ToString, Nothing, 0, IntPtr.Zero)
End If
Return _err
End Function
Public Function GetLastErrorMessage() As String
Dim returnData As New StringBuilder(128)
_err = mciGetErrorString(_err, returnData, 128)
Return returnData.ToString.Trim
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
CloseIt()
End Sub
End Class

How to record a specific applications audio? vb.net

How can I make an application that can record the audio output of another application using VB.net?
I've extracted some parts of my old TextToSpeek program.
The MCI-recording works very well. The Windows Mixer is included in all versions. So you can record the output of all programs. I hope I have not forgotten anything. Just ask then.
Private ActMediaFolder As String
Private RecAlias As String
Private MciRS As String = Space(1024)
Private MciRL As Integer = 1024
Private MciLength As Integer
Private mciStopped As Boolean
Private IsRecorded As Boolean = False
Private Mp3Quality As Integer
Private axMpIsInPlayState As Boolean = False
Public Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
#Region "MCI RECORDING"
Public Function MciOpen(ByVal sFile As String, ByVal sAlias As String) As Boolean
Try
mciSendString("close " & sAlias, 0, 0, 0)
' OPEN MCI:
If mciSendString("open " & Chr(34) & sFile & Chr(34) & _
" type waveaudio alias " & sAlias, 0, 0, 0) = 0 Then
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Private Sub MciRecord()
'Dim bits As String = "16"
'Dim samples As String = "44100"
'Dim bytes As String = "176400"
'Dim c As String = "2"
Try
Dim CB As Long = 0
mciSendString("close " & RecAlias, 0, 0, 0)
mciSendString("open new type waveaudio alias " & RecAlias, MciRS, 128, 0)
mciSendString("SET MyRec TIME FORMAT MS", MciRS, MciRL, CB)
mciSendString("SET MyRec BITSPERSAMPLE 16", MciRS, MciRL, CB)
mciSendString("SET MyRec CHANNELS 2", MciRS, MciRL, CB)
mciSendString("SET MyRec SAMPLESPERSEC 44100", MciRS, MciRL, CB)
mciSendString("SET MyRec BYTESPERSEC 176400", MciRS, MciRL, CB)
mciSendString("record " & RecAlias, MciRS, MciRL, CB)
IsRecorded = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub MciStopRecord()
TimerRecTime.Stop()
Try
mciSendString("stop " & RecAlias, MciRS, MciRL, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub MciPlayRecord()
Try
mciSendString("play " & RecAlias & " from 0", MciRS, MciRL, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub MciSaveRecord(ByVal sfile As String)
Try
mciSendString("save " & RecAlias & " " & Chr(34) & sfile & Chr(34), MciRS, MciRL, 0)
mciSendString("close " & RecAlias, MciRS, MciRL, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Function MciPlay(ByVal sfile As String, ByVal sAlias As String) As Boolean
Try
Dim sBuffer As String = Space(256)
MP3_Stop("MyAlias")
mciSendString("close MyAlias", 0, 0, 0)
mciSendString("open " & Chr(34) & sfile & Chr(34) & " ALIAS MyAlias", 0, 0, 0)
mciSendString("play MyAlias from 0", 0, 0, 0)
mciSendString("status MyAlias mode", sBuffer, Len(sBuffer), 0)
MsgBox(sBuffer)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Sub MP3_Stop(ByVal sAlias As String)
Try
mciSendString("stop " & sAlias, 0, 0, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Function mciGetLength() As Integer
Try
Dim sBuffer As String = Space(256)
mciSendString("status MyAlias length", sBuffer, Len(sBuffer), 0)
mciGetLength = Val(sBuffer)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Function mciCurPos() As Integer
Try
Dim sBuffer As String = Space(256)
mciSendString("status MyAlias position", sBuffer, Len(sBuffer), 0)
mciCurPos = Val(sBuffer)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Function mciGetStatus() As String
Try
Dim sBuffer As String = Space(256)
mciSendString("status MyAlias mode", sBuffer, Len(sBuffer), 0)
mciGetStatus = sBuffer
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return "Error"
End Function
Private Sub TimerMCI_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerMCI.Tick
Try
If InStr(mciGetStatus(), "stop") Then
mciStopped = True
MsgBox("STOP")
TimerMCI.Stop()
ElseIf InStr(mciGetStatus(), "Error") Then
mciStopped = True
MsgBox("ERROR")
TimerMCI.Stop()
Else
mciStopped = False
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
#End Region