Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 31st, 2005, 11:20 AM   #1
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
Post Time In MMControl

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
fox123 is offline   Reply With Quote
Old May 31st, 2005, 12:43 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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
As we're calculating the % elapsed, the time format is arbitrary, so frames (meaning individual moments of sound, like frames in a video) are used. If you want to display the actual HH:MMS, 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.
Rory is offline   Reply With Quote
Old May 31st, 2005, 1:25 PM   #3
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old May 31st, 2005, 2:03 PM   #4
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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
Rory is offline   Reply With Quote
Old May 31st, 2005, 2:25 PM   #5
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
Many Thanks Rory
fox123 is offline   Reply With Quote
Old May 31st, 2005, 2:27 PM   #6
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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 Function

Don't worry if you have no time
fox123
fox123 is offline   Reply With Quote
Old May 31st, 2005, 5:00 PM   #7
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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:MMS.mmm by dividing through by each range (1000,60,60) and subtracting the remainder. A similar effect can be achieve by format(x,"HH:MMS") but you wanted milliseconds as well.
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC