Results 1 to 2 of 2

Thread: (Resolved - I think) How to tell when mp3 is done playing?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Resolved (Resolved - I think) How to tell when mp3 is done playing?

    Hey All,

    I'm using Matthew Gates code to play an mp3 file.

    mciSendString API function

    I'm using one button to play and stop the file. When the user clicks the
    button to start the file playing, the caption changes to "stop". I'm trying
    to figure out how to tell when the file is finished playing, so I can have the
    caption automatically change back to "play".

    Any help would be greatly appreciated.

    Thanks,
    Ron
    Last edited by rdcody; Dec 15th, 2005 at 09:52 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: How to tell when mp3 is done playing?

    Well, this is the only way I could figure out how to do this...


    VB Code:
    1. Public Function GetCurrentMPEGPos() As Long
    2.  
    3. Dim dwReturn As Long
    4. Dim Pos As String * 255
    5.  
    6. dwReturn = mciSendString("status mpeg position", Pos, 255, 0&)
    7.  
    8. If Not dwReturn = 0 Then  'not success
    9.     GetCurrentMPEGPos = -1
    10.     Exit Function
    11. End If
    12.  
    13. GetCurrentMPEGPos = Val(Pos)
    14. End Function
    15.  
    16.  
    17.  
    18. Public Function GetTotalTimeByMS() As Long
    19. Dim dwReturn As Long
    20. Dim TotalTime As String * 255
    21.  
    22.  
    23. dwReturn = mciSendString("set mpeg time format ms", Total, 255, 0&)
    24. dwReturn = mciSendString("status mpeg length", TotalTime, 255, 0&)
    25.  
    26. mciSendString "set mpeg time format frames", Total, 255, 0& ' return focus to frames not to time
    27.  
    28. If Not dwReturn = 0 Then  'not success
    29.     GetTotalTimeByMS = -1
    30.     Exit Function
    31. End If
    32.  
    33. GetTotalTimeByMS = Val(TotalTime)
    34. End Function
    35.  
    36.  
    37.  
    38. 'Use it by placing it in a timer...
    39.  
    40. Private Sub Timer1_Timer()
    41. If GetCurrentMPEGPos >= GetTotalTimeByMS Then
    42.    Command1.Caption = "play"
    43. End If
    44. End Sub

    Seems to work ok.

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