VB.Net playing mp3 at the same time - vb.net

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

Related

How to get value from ComboBox and TextBox into Argument line?

I want to unzip a specific file with a external Program in VB.NET but, I don't know how to do that.
This is my attempt.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("7z.exe","-e" Textbox1.Text + Combobox1.Text )
End Sub
Instead of using the 7z.exe use the DLL they provide.
Public Class ArchivationHandling
Private Declare Function SevenZip Lib "7-zip32.dll" (ByVal hwnd As Integer, ByVal strCmdLine As String, ByVal strOutput As String, ByVal dwSize As Integer) As Long
Private bJobCompleted As Boolean = False
Private Const ZIP_EXTENSION As String = ".zip"
Private Const SEVEN_ZIP_PAR As String = vbNullString
Private Function Decompress(ByVal strZipPath As String, ByVal strOutPut As String) As Boolean
Dim strZipComm As String = "x -o" & strOutPut & " " & strZipPath & ZIP_EXTENSION & " -hide"
Try
SevenZip(0, strZipComm, SEVEN_ZIP_PAR, 0)
bJobCompleted = True
Catch ex As Exception
Logger.WriteLogEntry(4, "Decompression failed for file: " & strZipPath & " " & ex.Message.ToString)
End Try
Return bJobCompleted
End Function
Public ReadOnly Property Decompression(ByVal strZipFilePath As String, ByVal strOutput As String) As Boolean
Get
Return Decompress(strZipFilePath, strOutput)
End Get
End Property
End Class
This is an example of what I use in one of my applications.
You just provide the input file and output.

(VB.NET) Object reference not set to an instance of an object

This program works like this: User enters building name and number of floors, that gets validated and accepted. Then user enters rates for each floor until it goes through all floors, that data gets added to a listbox, then user enters a desired floor and it adds the rent and other info to another listbox lower down. As soon as I enter my number of floors and click on the button to save the info, the program runs into an error under btnEnterBuilding Click event where it says dblRates(intHowMany) = dblRent. The error is
"An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication5.exe
Additional information: Object reference not set to an instance of an object."
Any help would be greatly appreciated, thanks!
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Dim dblRates() As Double
Dim intHowMany As Integer = 0 'points to the next avail entry in the array
Private Function ValidateString(ByVal strText As String, strInput As String, strValue As String) As Boolean
If strText = Nothing Then
MessageBox.Show(strText & " Must Be Supplied", "Error")
Return False
Else
Return True
End If
End Function
Private Function ValidateInteger(ByVal strText As String,
ByVal strIn As String,
ByRef intValue As Integer,
ByVal intMinValue As Integer,
ByVal intMaxValue As Integer) As Boolean
If strIn = Nothing Then
MessageBox.Show(strText & " Must Be Supplied", "Error")
Return False
Else
If Integer.TryParse(strIn, intValue) = False Then
MessageBox.Show(strText & " Must Be A Whole Number", "Error")
Return False
Else
If intValue < intMinValue Or intValue > intMaxValue Then
MessageBox.Show("Outside of Number of " & strText & " Limits", "Error")
Return False
Else
Return True
End If
End If
End If
End Function
Private Function ValidateDouble(ByVal strText As String,
ByVal strDbl As String,
ByRef dblValue As Double,
ByVal dblMinValue As Double,
ByVal dblMaxValue As Double) As Boolean
If strDbl = Nothing Then
MessageBox.Show(strText & " Must Be Supplied", "Error")
Return False
Else
If Double.TryParse(strDbl, dblValue) = False Then
MessageBox.Show(strText & " Must Be A Whole Number", "Error")
Return False
Else
If dblValue < dblMinValue Or dblValue > dblMaxValue Then
MessageBox.Show("Outside of Number of " & strText & " Limits", "Error")
Return False
Else
Return True
End If
End If
End If
End Function
Private Sub Form1_Load(sender As Object,
e As EventArgs) Handles Me.Load
Me.grpBuilding.Enabled = True
Me.grpRents.Enabled = False
Me.grpDesiredFloor.Enabled = False
End Sub
Private Sub btnRents_Click(sender As Object,
e As EventArgs) _
Handles btnRents.Click
Dim strName, strFloors As String
Dim intFloors As Integer
strName = txtName.Text
strFloors = txtFloors.Text
intFloors = CInt(strFloors)
If ValidateString("Building name", Me.txtName.Text, strName) = True Then
If ValidateInteger("Number of floors", Me.txtFloors.Text, intFloors, 3, 20) = True Then
Me.grpBuilding.Enabled = False
Me.grpRents.Enabled = True
Me.grpDesiredFloor.Enabled = False
End If
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub btnEnterBuilding_Click(sender As Object,
e As EventArgs) _
Handles btnEnterBuilding.Click
Dim intFloors As Integer
Dim dblRent As Double
Dim strRent As String
strRent = txtRent.Text
dblRent = CDbl(strRent)
If ValidateDouble("Rent", Me.txtRent.Text, dblRent, 1000.0, 2500.0) = True Then
dblRates(intHowMany) = dblRent
Me.txtRent.Focus()
Me.txtRent.SelectAll()
Me.ListBox1.Items.Add("Floor No. " & intHowMany.ToString("N0") &
" -- Rent Is: " & dblRent.ToString("N$"))
If intHowMany < intFloors Then
intHowMany += 1
Else
Me.grpBuilding.Enabled = False
Me.grpRents.Enabled = False
Me.grpDesiredFloor.Enabled = True
End If
Else
Me.txtRent.Focus()
Me.txtRent.SelectAll()
End If
End Sub
Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click
Dim intFloors, intFloor As Integer
Dim strName, strFloors As String
strName = txtName.Text
strFloors = txtFloors.Text
intFloors = CInt(strFloors)
If ValidateInteger("Desired Floor", Me.txtFloor.Text, intFloor, 3, 20) = False Then
MessageBox.Show("Please enter a valid floor number", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Me.lstDisplay.Items.Add("Building Name: " & strName & " # of Floors: " & intFloors.ToString)
Me.lstDisplay.Items.Add("Desired Floor: " & intFloor.ToString)
Me.lstDisplay.Items.Add(" Rent: " & intFloors.ToString)
End If
End Sub
End Class
You can't dim dblRates() as double like this without giving it initial values. You will need to dim dblRates(<some amount>) as Double and then redim it if necessary to add more values to it. Or you could Dim dblRates() as double = {0} but if you still want to add more values to the array, you will still need to redim it as the second options would just create an array of 1 element.

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

Fails playing a WAV file

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

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