Results 1 to 13 of 13

Thread: [RESOLVED] How to play sound from memory using mciSendString API

Threaded View

  1. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to play sound from memory using mciSendString API

    @namrekka

    I haven't tried it out yet but I see, although it is from the winmm.dll, I see that it does not use mciSendString explicitly so I am wondering if it has the same return messages as mciSendString API. I have a current project that is using mciSendString and in the code it returns info that I need to perform a certain feature as it is playing a sound file.

    Here is a code snippet from that project that I require:

    Code:
    Dim Multimedia As MMedia
    Dim sngLength As Single
      '
      '
    Private Sub Timer1_Timer()
     Dim sngPosition As Single
     Dim sngPercent As Single
     Dim intX As Integer
    
     sngPosition = Multimedia.Position
        
     Label1.Caption = "Status: " & Multimedia.Status
        
     sngPercent = sngPosition / sngLength
     intX = (PicChannel.ScaleWidth - Screen.TwipsPerPixelX) * sngPercent
     
     L = Pic1Left + intX
     W = Pic1Width - intX
     
    Picture1.Move L, Picture1.Top, W, Picture1.Height
      '
      '
      '
    End Sub
    And in the Class Module I have:

    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
      '
      '
    Public Sub mmPlay()
     '   Plays the currently open file from the current position
     Dim lngReturn As Long   '   Hold the value returned by the mciSendString command
    
     '   If there is no file open then exit the sub
     If strAlias = "" Then
       Exit Sub
     End If
        
     If blnWait Then
       lngReturn = mciSendString("Play " & strAlias & " wait", "", 0, 0)
     Else
       lngReturn = mciSendString("Play " & strAlias, "", 0, 0)
     End If
    End Sub
      '
      '
    Public Property Get Position() As Single
     '   Returns the current position in the file
     Dim lngReturn As Long       '   Hold the value returned by the mciSendString
     Dim intLength As Integer
     Dim strPosition As String * 255     '   Holds the returned length from the mci
                                             '   status call
    
     '   Exit the property if there is no file open
     If strAlias = "" Then
       Exit Property
     End If
        
     '   Get the position and return
     lngReturn = mciSendString("Status " & strAlias & " position", strPosition, 255, 0)
     intLength = InStr(strPosition, Chr(0))
     Position = Val(Left(strPosition, intLength - 1))
    End Property
    
      '
      '
    The value controls the movement of a vertical bar moving left to right across a picturebox which is representing the amount of playing time that has elapsed. So far the only API that has made it possible for me to get a precise timing on the playing time is the mciSendString. How can I use your code to get the same results?

    As I looked through the code I fail to see where/how it plays sounds and how it gets the sound to play from a buffer. Isn't there a commands like wavOutPlay, waveOutStop, etc
    Last edited by jmsrickland; May 19th, 2013 at 04:32 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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