Results 1 to 6 of 6

Thread: MP3 And CD

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Hi,

    Do any of you have any code that will play an MP3 file and coe to play a CD. I do not want to use a control for it like the MS one.

    Any Ideas ?

  2. #2
    Guest
    here is a module that has MP3 playing functions.
    BTW this module contains some extra code, like always on top, and dragging a form, because i used it in one of my programs, and it needed these.
    Code:
    Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public TheFileName As String
    
    
    
    Public Function IsItPlaying() As Boolean
    Static yn As String * 30
        mciSendString "status MP3Play mode", yn, Len(yn), 0
        IsPlaying = (Mid$(yn, 1, 7) = "playing")
    End Function
    
    Public Function mp3Play(FileName As String)
    Dim cmdToDo As String * 255
    Dim dwReturn As Long
    Dim ret As String * 128
    
    Dim tmp As String * 255
    Dim lenShort As Long
    Dim ShortPathAndFie As String
        
        If Dir(FileName) = "" Then
            mmOpen = "Error with input file"
            Exit Function
        End If
        lenShort = GetShortPathName(FileName, tmp, 255)
        ShortPathAndFie = Left$(tmp, lenShort)
        glo_hWnd = hwnd
        cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias MP3Play"
        dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
    
        If dwReturn <> 0 Then  'not success
            mciGetErrorString dwReturn, ret, 128
            mmOpen = ret
            MsgBox ret, vbCritical
            Exit Function
        End If
        
        mmOpen = "Success"
        mciSendString "play MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Pause()
        mciSendString "pause MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Stop() As String
        mciSendString "stop MP3Play", 0, 0, 0
        mciSendString "close MP3Play", 0, 0, 0
    End Function
    
    Public Function PositionInSec()
    Static PIS As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", PIS, Len(PIS), 0
        PositionInSec = Round(Mid$(PIS, 1, Len(PIS)) / 1000)
    End Function
    
    Public Function Position()
    Static P As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", P, Len(P), 0
        sec = Round(Mid$(P, 1, Len(P)) / 1000)
        If sec < 60 Then Position = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Position = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    Public Function LengthInSec()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(s), 0
        LengthInSec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(s, 1, Len(s))) / 1000)
    End Function
    
    Public Function Length()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(L), 0
        sec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(l, 1, Len(l))) / 1000)
        If sec < 60 Then Length = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Length = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    
    Public Function SeekTo(Second)
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        If IsItPlaying = True Then mciSendString "play MP3Play from " & Second, 0, 0, 0
        If IsItPlaying = False Then mciSendString "seek MP3Play to " & Second, 0, 0, 0
    End Function
    
    Public Sub FormDrag(frm As Form)
    ReleaseCapture
    Call SendMessage(frm.hwnd, 161, 2, 0&)
    End Sub
    
    Public Sub FormOnTop(frm As Form, OTTF As Boolean)
      Select Case OTTF
        Case True
          Call SetWindowPos(frm.hwnd, HWND_TOPMOST, 0, 0 _
            , 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
        Case False
          Call SetWindowPos(frm.hwnd, HWND_NOTOPMOST, 0, 0 _
            , 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
      End Select
    End Sub
    
    Public Function RevInStr(ByVal sIn As String, sFind As String, Optional nStart As Long = 1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As Long
    Dim nPos As Long
        nPos = InStr(nStart, sIn, sFind, bCompare)
        If nPos = 0 Then
            RevInStr = 0
        Else
            RevInStr = Len(sIn) - nPos - Len(sFind) + 2
        End If
    End Function
    [Edited by denniswrenn on 08-21-2000 at 06:17 PM]

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    uh.........yeah, I remembered that off the top of my head...........I feel dumb

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    btw there was that odd smiley bug in the code window so heres it disabled:
    Code:
    Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public TheFileName As String
    
    
    
    Public Function IsItPlaying() As Boolean
    Static yn As String * 30
        mciSendString "status MP3Play mode", yn, Len(yn), 0
        IsPlaying = (Mid$(yn, 1, 7) = "playing")
    End Function
    
    Public Function mp3Play(FileName As String)
    Dim cmdToDo As String * 255
    Dim dwReturn As Long
    Dim ret As String * 128
    
    Dim tmp As String * 255
    Dim lenShort As Long
    Dim ShortPathAndFie As String
        
        If Dir(FileName) = "" Then
            mmOpen = "Error with input file"
            Exit Function
        End If
        lenShort = GetShortPathName(FileName, tmp, 255)
        ShortPathAndFie = Left$(tmp, lenShort)
        glo_hWnd = hwnd
        cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias MP3Play"
        dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&
    
        If dwReturn <> 0 Then  'not success
            mciGetErrorString dwReturn, ret, 128
            mmOpen = ret
            MsgBox ret, vbCritical
            Exit Function
        End If
        
        mmOpen = "Success"
        mciSendString "play MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Pause()
        mciSendString "pause MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Stop() As String
        mciSendString "stop MP3Play", 0, 0, 0
        mciSendString "close MP3Play", 0, 0, 0
    End Function
    
    Public Function PositionInSec()
    Static PIS As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", PIS, Len(PIS), 0
        PositionInSec = Round(Mid$(PIS, 1, Len(PIS)) / 1000)
    End Function
    
    Public Function Position()
    Static P As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", P, Len(P), 0
        sec = Round(Mid$(P, 1, Len(P)) / 1000)
        If sec < 60 Then Position = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Position = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    Public Function LengthInSec()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(s), 0
        LengthInSec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(s, 1, Len(s))) / 1000)
    End Function
    
    Public Function Length()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(L), 0
        sec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(l, 1, Len(l))) / 1000)
        If sec < 60 Then Length = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Length = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    
    Public Function SeekTo(Second)
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        If IsItPlaying = True Then mciSendString "play MP3Play from " & Second, 0, 0, 0
        If IsItPlaying = False Then mciSendString "seek MP3Play to " & Second, 0, 0, 0
    End Function
    
    Public Sub FormDrag(frm As Form)
    ReleaseCapture
    Call SendMessage(frm.hwnd, 161, 2, 0&
    End Sub
    
    Public Sub FormOnTop(frm As Form, OTTF As Boolean)
      Select Case OTTF
        Case True
          Call SetWindowPos(frm.hwnd, HWND_TOPMOST, 0, 0 _
            , 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
        Case False
          Call SetWindowPos(frm.hwnd, HWND_NOTOPMOST, 0, 0 _
            , 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
      End Select
    End Sub
    
    Public Function RevInStr(ByVal sIn As String, sFind As String, Optional nStart As Long = 1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As Long
    Dim nPos As Long
        nPos = InStr(nStart, sIn, sFind, bCompare)
        If nPos = 0 Then
            RevInStr = 0
        Else
            RevInStr = Len(sIn) - nPos - Len(sFind) + 2
        End If
    End Function

  5. #5
    Guest
    And here's the link to play a CD. Make a CD Player, actually.




  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Thankyou very much guys.

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