Results 1 to 8 of 8

Thread: [VB6] - mcisendstring() api function delay problem

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    [VB6] - mcisendstring() api function delay problem

    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6] - mcisendstring() api function delay problem

    Quote Originally Posted by RhinoBull View Post
    Try using PlaySound function.
    more limited in formats and have the same effect
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6] - mcisendstring() api function delay problem

    Quote Originally Posted by RhinoBull View Post
    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:
    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
    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.
    thanks
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [VB6] - mcisendstring() api function delay problem

    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.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6] - mcisendstring() api function delay problem

    Quote Originally Posted by RhinoBull View Post
    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.
    Code:
    Dim strFileName As String
        CommonDialog1.ShowOpen
        strFileName = GetShortPathName(CommonDialog1.FileName, 0&, 0&)
        mciSendString "Play " & strFileName, "", 0, 0
    i try without GetShortPathName() but in both ways don't play. did i forget something?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6] - mcisendstring() api function delay problem

    ok.. now works:
    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
    but the delay continues. why GetShortFileName() function?
    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?
    Last edited by joaquim; May 3rd, 2011 at 08:29 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width