|
-
Nov 13th, 2005, 10:59 AM
#1
Thread Starter
Addicted Member
Problems playing a CD
Hello. I have created a CD player using mciSendStrings, but I am having trouble getting the current track. For some reason, the code below is always returning the current track as "1":
VB Code:
Public getCurrentTrack As Integer = Nothing
Sub CDplay()
Try
Dim totalTime As String = Space(128)
mciSendString("close " & TheFile, CStr(0), 0, 0)
TheFile = Chr(34) & Trim(MP3File) & Chr(34)
mciSendString("open " & TheFile, CStr(0), 0, 0)
mciSendString("Set " & TheFile & " time format TMSF", 0, 0, 0)
mciSendString("Status " & TheFile & " current track", totalTime, 128, 0)
getCurrentTrack = Val(totalTime)
If getNumberTracks() = track Then
mciSendString("Play " & TheFile & " from " & getCurrentTrack, 0, 0, 0)
Else
mciSendString("Play " & TheFile & " from " & getCurrentTrack & " to " & getCurrentTrack + 1, 0, 0, 0)
End If
Catch exc As Exception
MessageBox.Show(exc.Message, "Error!", MessageBoxButtons.OK)
End Try
End Sub
A programmer is a person who fixes a problem you did not know you had in a way that you cannot understand.
-
Nov 13th, 2005, 05:57 PM
#2
Re: Problems playing a CD
I don't quite understand why you have a string called "totalTime" that is giving you the track number. Is it the time or the track number? If it's the time then I'd guess that that's you issue, but if it's the track number then you've used a confusing naming convention. Also, from a coding style perspective, a variable should not be called "getCurrentTrack". That would be an appropriate name for a method that actually gets the number, but just "currentTrack" or "currentTrackNumber" would be more appropriate for a variable. variable and property names should be nouns becasue they ARE something, while method names should generally be or include verbs as they DO something. Finally, I'd suggest avoiding the use of so many Runtime functions. There's obviously been a wealth of debate on their merits and I don't see them as evil like some, but I do believe that they should be second choice to System-based alternatives. I also believe that the Val function works in a counter-intuitive fashion, and it might be the problem if you have non numerical characters in that "totalTime" variable.
-
Nov 14th, 2005, 12:43 AM
#3
Re: Problems playing a CD
Why are you passing a filename if you are creating a CD player?
The command you want is, I think, "status cd position". Instead of calling Val() on it you should use .Substring(totalTime, 1, 2) although, as jmcilhinney points out, you really should give it a better name
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|