Results 1 to 3 of 3

Thread: Problems playing a CD

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    202

    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:
    1. Public getCurrentTrack As Integer = Nothing
    2.  
    3. Sub CDplay()
    4.         Try
    5.             Dim totalTime As String = Space(128)
    6.             mciSendString("close " & TheFile, CStr(0), 0, 0)
    7.             TheFile = Chr(34) & Trim(MP3File) & Chr(34)
    8.             mciSendString("open " & TheFile, CStr(0), 0, 0)
    9.             mciSendString("Set " & TheFile & " time format TMSF", 0, 0, 0)
    10.             mciSendString("Status " & TheFile & " current track", totalTime, 128, 0)
    11.             getCurrentTrack = Val(totalTime)
    12.             If getNumberTracks() = track Then
    13.                 mciSendString("Play " & TheFile & " from " & getCurrentTrack, 0, 0, 0)
    14.             Else
    15.                 mciSendString("Play " & TheFile & " from " & getCurrentTrack & " to " & getCurrentTrack + 1, 0, 0, 0)
    16.             End If
    17.         Catch exc As Exception
    18.             MessageBox.Show(exc.Message, "Error!", MessageBoxButtons.OK)
    19.         End Try
    20.     End Sub
    A programmer is a person who fixes a problem you did not know you had in a way that you cannot understand.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width