using mcisendstring() api function, when you play the sound, you see a delay(by some seconds). is possible avoid these delay?
there is another function so powerfull(only for audio) that can avoid these delay?
Printable View
using mcisendstring() api function, when you play the sound, you see a delay(by some seconds). is possible avoid these delay?
there is another function so powerfull(only for audio) that can avoid these delay?
Try using PlaySound function.
Maybe you can post your code as I have no clue what delays are you talking about - it could be something in your own program.
ok.. heres my class.
and how use it:
use my class and choose mp3 or wave or mid. then you will see 1 delay befor play it. and then tell me if it's normal or not.Code:Dim Sound As New Sound
Sound.FileName = CommonDialog1.FileName 'change the filename(string)
Sound.SoundPlay 'play's the audio file
sound.soundstop 'stop's the audio file
thanks
Your FileOpen method is calling 4 functions:
ValidFile(FileName) = False Then Exit Sub
strShorFileName = GetShortFileName(strFileName)
nReturn = mciSendString("Open " & strShorFileName & " wait", "", 0, 0)
nReturn = mciSendString("setaudio " & strFileName & " volume to " & (lngVolume * 10), "", 0, 0)
Also, your SoundPlay method has bunch of activities going on there as well...
It doesn't look like it should delay you but try excuting mciSendString or PlaySound directly to make sure either function works without delays.
ok.. now works:
but the delay continues. why GetShortFileName() function?Code:Private 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
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Const MAX_PATH As Long = 260
Dim strFileName As String
Private Sub Command1_Click()
CommonDialog1.ShowOpen
strFileName = GetShortFileName(CommonDialog1.FileName)
mciSendString "play " & strFileName, "", 0, 0
End Sub
Private Function GetShortFileName(ByVal sFileName As String) As String
Dim sBuffer As String
sBuffer = String$(MAX_PATH, vbNullChar)
Call GetShortPathName(sFileName, sBuffer, MAX_PATH)
GetShortFileName = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
End Function
Private Sub Command2_Click()
mciSendString "stop " & strFileName, "", 0, 0
End Sub
is for i use the file name, or the mcisendstring() don't works.
in mcisendstring(), why a short file name instead a normal file name?