![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
This has got me really stuck. It seeme quite simple but i cannot find a soloution.
What i want to happen is for the user to press a button and the current progress/time of the song is coppied to the clipboard. All i need to know is how to get the time from the media control. I hope that makes sense. Thanks |
|
|
|
|
|
#2 |
|
Expert Programmer
|
This should do it:
Private Sub Form_Click() VB.Clipboard.SetText Round(MMControl1.Position / MMControl1.Length * 100) & " % elapsed" End Sub Private Sub Form_Load() MMControl1.FileName = "C:\Windows\Media\Tada.wav" MMControl1.Command = "Open" MMControl1.TimeFormat = mciFormatFrames 'Sets the time format to frames End Sub S, check http://msdn.microsoft.com/library/de...imefmt_mci.asp for information on decoding the various time formats.However, if you're running XP there is a bug with the clipboard object in VB IDE (it doesn't work!), but not when compiled: try doing debug.print to see the results. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
Thanks for the help.
I am trying to get the Coppied progress in minutes and seconds. I changed your code to this Private Sub Command1_Click() VB.Clipboard.Clear ' Added this so the command can be done numerous times VB.Clipboard.SetText Round(MMControl1.Position / MMControl1.Length * 100) & " % elapsed" End Sub Private Sub Form_Load() MMControl1.FileName = frmPath.txtPath MMControl1.Command = "Open" MMControl1.TimeFormat = mciFormatMsf 'Sets the time format to frames End Sub However when i paste the text it is still displayed as % Elasped. Any Ideas Thanks for your time |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Well it's not your fault: Microsoft can't be bothered to fix their buggy code
http://support.microsoft.com/kb/q94012/ so the only available time format is Milliseconds. Grrr! So as a workaround, the following code should work: Private Sub Form_Click()
VB.Clipboard.SetText MillisecondsToTimeString(MMControl1.Position) & _
" / " & MillisecondsToTimeString(MMControl1.Length)
End Sub
Private Sub Form_Load()
MMControl1.FileName = "C:\Windows\Media\Tada.wav"
MMControl1.Command = "Open"
MMControl1.TimeFormat = mciFormatMilliseconds
End Sub
Private Function MillisecondsToTimeString(ByVal nLength As Long) As String
Dim nBuffer As Long
Dim nMilliseconds As Long
Dim nSeconds As Long
Dim nMinutes As Long
Dim nHours As Long
nMilliseconds = nLength Mod 1000
nBuffer = (nLength - nMilliseconds) / 1000
nSeconds = nBuffer Mod 60
nBuffer = (nBuffer - nSeconds) / 60
nMinutes = nBuffer Mod 60
nBuffer = (nBuffer - Minutes) / 60
nHours = nBuffer Mod 60
nBuffer = (nBuffer - nHours) / 60
MillisecondsToTimeString = Format(nHours, "00") & ":" & Format(nMinutes, "00") & ":" & Format(nSeconds, "00") & "." & Format(nMilliseconds, "000")
End Function |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
Many Thanks Rory
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
the code worked well but
Could you explain the code so i can learn from it: Private Function MillisecondsToTimeString(ByVal nLength As Long) As String
Dim nBuffer As Long
Dim nMilliseconds As Long
Dim nSeconds As Long
Dim nMinutes As Long
Dim nHours As Long
nMilliseconds = nLength Mod 1000
nBuffer = (nLength - nMilliseconds) / 1000
nSeconds = nBuffer Mod 60
nBuffer = (nBuffer - nSeconds) / 60
nMinutes = nBuffer Mod 60
nBuffer = (nBuffer - Minutes) / 60
nHours = nBuffer Mod 60
nBuffer = (nBuffer - nHours) / 60
MillisecondsToTimeString = Format(nHours, "00") & ":" & Format(nMinutes, "00") & ":" & Format(nSeconds, "00") & "." & Format(nMilliseconds, "000")
End FunctionDon't worry if you have no time fox123 |
|
|
|
|
|
#7 |
|
Expert Programmer
|
Well what that particular function does is not complicated, just maths really. It takes in a numeric long variable representing a number of milliseconds, and return a string in the form HH:MM
S.mmm by dividing through by each range (1000,60,60) and subtracting the remainder. A similar effect can be achieve by format(x,"HH:MM S") but you wanted milliseconds as well. ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|