Results 1 to 1 of 1

Thread: VB5/6 - Super Simpler MP3 & MPG player code for your project

  1. #1

    Thread Starter
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    VB5/6 - Super Simpler MP3 & MPG player code for your project

    You'll need 1 form with 1 listbox.
    Add the code below - it will read the My Music directory.
    Post Edited - Browsing allowed

    Code:
    Option Explicit
    Private Const LB_DIR = &H18D
    Private Const DIR_NORMALFILES = &H0
    Private Const DDL_DIRECTORY = &H10
    Private Const DDL_DRIVES = &H4000
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    'Declaration for the winmm dll
    Private 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
    Private Sub Form_Load()
    Me.Show
    ChDir Environ("USERPROFILE") & "\My Documents\My Music\"
    SendMessage List1.hwnd, LB_DIR, DDL_DRIVES Or DDL_DIRECTORY, ".\*.*"
    
    End Sub
    Public Function Play_MM(song As String)
        Dim shortpath As String, pathlength As Long
        shortpath = Space(250)
        pathlength = GetShortPathName(song, shortpath, Len(shortpath))
        If pathlength Then
            shortpath = Left$(shortpath, pathlength)
        End If
        mciSendString "Close MM", 0, 0, 0
        mciSendString "Open " & shortpath & " Alias MM", 0, 0, 0
        If LCase(Right(shortpath, 3)) = "mpg" Then
            mciSendString "Window MM state show", 0, 0, 0
        Else
            mciSendString "Window MM state hide", 0, 0, 0
        End If
        
        mciSendString "Play MM", 0, 0, 0
        
    End Function
    Private Sub Form_Unload(Cancel As Integer)
    mciSendString "Close MM", 0, 0, 0
    End
    End Sub
    
    Private Sub List1_Click()
    Dim x As String
    x = List1.List(List1.ListIndex)
    On Error GoTo er
    If Left(x, 2) = "[-" Then
        ChDrive Mid(x, 3, 1)
        List1.Clear
        SendMessage List1.hwnd, LB_DIR, DDL_DRIVES Or DDL_DIRECTORY, ".\*.*"
    ElseIf Left(x, 3) = "[.." Then
        ChDir ".."
        List1.Clear
        SendMessage List1.hwnd, LB_DIR, DDL_DRIVES Or DDL_DIRECTORY, ".\*.*"
    ElseIf Left(x, 1) = "[" Then
        ChDir ".\" & Mid(x, 2, Len(x) - 2)
        List1.Clear
        SendMessage List1.hwnd, LB_DIR, DDL_DRIVES Or DDL_DIRECTORY, ".\*.*"
    Else
        Play_MM CurDir & "\" & List1.List(List1.ListIndex)
    End If
    Exit Sub
    er:
    MsgBox Err.Description
    End Sub
    Last edited by technorobbo; Feb 20th, 2009 at 09:12 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

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