Results 1 to 11 of 11
  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    Ensure Function Completes Before Continuing to Next Row in Recordset

    Ok .. well here is a weird one. Normally you want things to be fast .. but in my case, I want things to be slow.

    So .. I have some .wav files and I want them to be played in succession.

    I have a table with file paths in there and I use a play audio function to play them. That is fine, as long as I play 1 file.

    I have a recordset with the path data for the selected files that I want to play .. but it only plays the last one as it whips through them quickly.

    How do I make it go and play one file at a time ? So play file 1 .. then 2 after 1 has completed playing etc.

    Here is my code ...

    ' RECORDSET .. rstEdits.Fields(1) contains the paths from the table.

    If rstEdits.EOF Then Exit Sub

    With rstEdits

    .MoveFirst

    Do Until .EOF

    PlaySound (rstEdits.Fields(1))

    .MoveNext

    Loop
    End With

    ' FUNCTION TO PLAY SOUND

    Function PlaySound(sWavFile As String)

    ' Purpose: Plays a sound.


    ' Argument: the full path and file name.

    'Source: http://allenbrowne.com
    'Adapted from: http://allenbrowne.com

    If apisndPlaySound(sWavFile, 1) = 0 Then
    MsgBox "The Sound Did Not Play!"
    End If


    End Function

    ' TABLE DATA WITH FILE PATHS

    1 c:\users\kevin.win8\desktop\536 audio\2016-12-31\2016-12-29_18-42-43.wav
    2 c:\users\kevin.win8\desktop\536 audio\2016-12-31\2016-12-29_18-42-44.wav
    3 c:\users\kevin.win8\desktop\536 audio\2016-12-31\2016-12-29_18-42-49.wav

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    If the PLAYSOUND launches another app,(player) then access is free to move on.
    Access has nothing to do with that app so it goes to the next wav.

    youd need a MsgBox to stop after each wav,and ask Continue? To stay in the loop.

  3. #3
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Quote Originally Posted by ranman256 View Post
    If the PLAYSOUND launches another app,(player) then access is free to move on.
    Access has nothing to do with that app so it goes to the next wav.

    youd need a MsgBox to stop after each wav,and ask Continue? To stay in the loop.
    It doesn't use an app is just tells windows to play the file. Putting in a MsgBox is not an option.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can use this to pause the code:

    http://access.mvps.org/access/api/api0021.htm

    You could add a duration field to your table to control how long.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    EDIT .. I may have a solution. I can use the SLEEP code you posted, but I need to set a random 'sleep length' based on the time of the file.
    I will see about doing that. Until then .. I will work on it.

    I have used this in the past .. but it does not work here. I have used it for like a batch file .. so that Access waits until it is finished.


    Sub RunAppWait(strCommand As String, intMode As Integer)
    ' Run an application, waiting for its completion
    ' before returning to the caller.

    Dim TotalElapsedMilliSec As Long

    Const PROCESS_QUERY_INFORMATION = &H400
    Const SYNCHRONIZE = &H100000

    Const STILL_ACTIVE = &H103&

    Dim hInstance As Long
    Dim hProcess As Long
    Dim lngExitCode As Long

    On Error GoTo HandleError
    ' Start up the application.
    hInstance = Shell(strCommand, intMode)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
    True, hInstance)
    Do
    ' Attempt to retrieve the exit code, which will
    ' not exist until the application has quit.
    Call GetExitCodeProcess(hProcess, lngExitCode)
    DoEvents

    Loop Until lngExitCode <> STILL_ACTIVE

    TotalElapsedMilliSec = 0
    Forms!frmBackup.TimerInterval = 0

    ExitHere:
    Exit Sub

    HandleError:
    Select Case Err.Number
    Case errFileNotFound
    MsgBox "Unable to find '" & strCommand & "'"
    Case Else
    MsgBox Err.Description
    End Select
    Resume ExitHere
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Not sure what the difference between pausing and waiting is, but like I said, you could add a duration field to your table with files and have the code wait that long before playing the next file.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    I do apologize saying that it would not work .. it does, but I need to calculate the length of each file. That may be a bit tricky.
    But I will see what I can do. I am fine with adding that to the table .. as I am not going to be dealing with a lot of files at once.

    So .. thanks, I am sure that someone will appreciate this as well in the future.
    Btw .. the code I posted above does work for things like batch files that are external to Access.

    Btw .. found this code that may give me what I want.

    Private Sub Command1_Click()
    Dim MyInt As Integer
    Dim MyByte As Byte
    Dim MyStr As String * 4
    Dim MyLong As Long
    Dim SampleRate, BytesPerSample, FileSize As Long

    Open "d:\tmp.wav" For Binary Access Read Lock Read As #1
    Get #1, , MyStr: Debug.Print "Riff = "; MyStr
    Get #1, , MyLong: Debug.Print "File size = "; MyLong
    FileSize = MyLong
    Get #1, , MyStr: Debug.Print "Wave = "; MyStr
    Get #1, , MyStr: Debug.Print "Format = "; MyStr
    Get #1, , MyLong: Debug.Print "Any = "; MyLong
    Get #1, , MyInt: Debug.Print "formatTag = "; MyInt
    Get #1, , MyInt: Debug.Print "Channels = "; MyInt
    Get #1, , MyLong: Debug.Print "Samples per Sec = "; MyLong
    SampleRate = MyLong
    Get #1, , MyInt: Debug.Print "Bytes per Sec = "; MyInt
    Get #1, , MyInt: Debug.Print "BlockAlign = "; MyInt
    Get #1, , MyInt: Debug.Print "Bytes per Sample = "; MyInt
    BytesPerSample = MyInt
    Close #1
    Debug.Print "Wave File Duration = "; _
    FileSize / (SampleRate * BytesPerSample); " seconds"
    End Sub

  8. #8
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Quote Originally Posted by edmscan View Post
    I do apologize saying that it would not work .. it does, but I need to calculate the length of each file. That may be a bit tricky.
    But I will see what I can do. I am fine with adding that to the table .. as I am not going to be dealing with a lot of files at once.

    So .. thanks, I am sure that someone will appreciate this as well in the future.
    Btw .. the code I posted above does work for things like batch files that are external to Access.

    Btw .. found this code that may give me what I want.

    Private Sub Command1_Click()
    Dim MyInt As Integer
    Dim MyByte As Byte
    Dim MyStr As String * 4
    Dim MyLong As Long
    Dim SampleRate, BytesPerSample, FileSize As Long

    Open "d:\tmp.wav" For Binary Access Read Lock Read As #1
    Get #1, , MyStr: Debug.Print "Riff = "; MyStr
    Get #1, , MyLong: Debug.Print "File size = "; MyLong
    FileSize = MyLong
    Get #1, , MyStr: Debug.Print "Wave = "; MyStr
    Get #1, , MyStr: Debug.Print "Format = "; MyStr
    Get #1, , MyLong: Debug.Print "Any = "; MyLong
    Get #1, , MyInt: Debug.Print "formatTag = "; MyInt
    Get #1, , MyInt: Debug.Print "Channels = "; MyInt
    Get #1, , MyLong: Debug.Print "Samples per Sec = "; MyLong
    SampleRate = MyLong
    Get #1, , MyInt: Debug.Print "Bytes per Sec = "; MyInt
    Get #1, , MyInt: Debug.Print "BlockAlign = "; MyInt
    Get #1, , MyInt: Debug.Print "Bytes per Sample = "; MyInt
    BytesPerSample = MyInt
    Close #1
    Debug.Print "Wave File Duration = "; _
    FileSize / (SampleRate * BytesPerSample); " seconds"
    End Sub
    In the end .. I determined that the files are 16,384 bits per second (16 kbps), that will remain constant in my use. So .. I just got the file size in bits from the header of the wav file using the code above and then .. set the sleep time to be about that time ... plus a bit more to make listening a bit better. So .. this is a done deal.

    Thanks ..
    Kevin

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    have to admit I've never dabbled in this, but I've read where others created a playlist from a recordset. Then you wouldn't have to worry about bit or compression rates, or file length (which you'd think is an extended attribute, but I couldn't find it). A playlist file looks like this
    Code:
    <?wpl version="1.0"?>
    <smil>
        <head>
            <meta name="QInfo" content="KAAoAEQAaQBzAHAAbABhAHkAQQByAHQAaQBzAHQAIABFAHEAdQBhAGwAcwAgACIAQgBvAHMAdABvAG4AIgApACkA;MAA=;TABvAGMAYQBsAE0ATABTAA==;;MAAtAA==;;LQAxAA==;;;ZgBhAGwAcwBlAA==;MAAtAA==;ZgBhAGwAcwBlAA==;MAAtAA=="/>
            <meta name="Generator" content="Microsoft Windows Media Player -- 12.0.7601.23517"/>
            <meta name="IsNetworkFeed" content="0"/>
            <meta name="ItemCount" content="8"/>
            <title>Boston</title>
        </head>
        <body>
            <seq>
                <media src="..\Boston\01More Than a Feeling.mp3" cid="{88905553-1981-4442-9BDD-B40B0814CE6D}" tid="{EE61CFA7-A11D-4E7C-9292-D797077A922A}"/>
                <media src="..\Boston\02Peace of Mind.mp3"/>
                <media src="..\Boston\03Foreplay_Long Time.mp3"/>
                <media src="..\Boston\04Rock&amp;Roll Band.mp3"/>
                <media src="..\Boston\05Smokin.mp3"/>
                <media src="..\Boston\06Hitch a Ride.mp3"/>
                <media src="..\Boston\07Somethin About You.mp3"/>
                <media src="..\Boston\08Let Me Take You Home Tonight.mp3"/>
            </seq>
        </body>
    </smil>
    Sorry, I don't know much about the meta tags. It's just that I was so intrigued by this that I spent hours on trying to ascertain those attributes, or the properties of media files that 'mark' them as in use that I hate to waste the conclusion and thought it might help somebody some day.

    Hope I'm not giving away my age or nuthin by that play list...
    Last edited by Micron; 01-02-2017 at 01:54 AM. Reason: spelin
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I've got that album too. I guess we're both old.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Pass DAO.Recordset into public function
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 07-07-2014, 12:31 AM
  2. Pass recordset field into function
    By Ruegen in forum Programming
    Replies: 6
    Last Post: 04-13-2014, 11:04 PM
  3. Retreiving a recordset from a function
    By nigelbloomy in forum Programming
    Replies: 9
    Last Post: 02-22-2014, 08:36 AM
  4. Report Restarts Itself And Never Completes
    By VariableZ in forum Reports
    Replies: 10
    Last Post: 03-01-2012, 10:47 PM
  5. Replies: 6
    Last Post: 11-16-2010, 02:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums