(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
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:
Public Function GetCurrentMPEGPos() As Long
Dim dwReturn As Long
Dim Pos As String * 255
dwReturn = mciSendString("status mpeg position", Pos, 255, 0&)
If Not dwReturn = 0 Then 'not success
GetCurrentMPEGPos = -1
Exit Function
End If
GetCurrentMPEGPos = Val(Pos)
End Function
Public Function GetTotalTimeByMS() As Long
Dim dwReturn As Long
Dim TotalTime As String * 255
dwReturn = mciSendString("set mpeg time format ms", Total, 255, 0&)
dwReturn = mciSendString("status mpeg length", TotalTime, 255, 0&)
mciSendString "set mpeg time format frames", Total, 255, 0& ' return focus to frames not to time
If Not dwReturn = 0 Then 'not success
GetTotalTimeByMS = -1
Exit Function
End If
GetTotalTimeByMS = Val(TotalTime)
End Function
'Use it by placing it in a timer...
Private Sub Timer1_Timer()
If GetCurrentMPEGPos >= GetTotalTimeByMS Then
Command1.Caption = "play"
End If
End Sub
Seems to work ok.