Results 1 to 7 of 7

Thread: Loading Winamps m3u playlist to a ListBox question

  1. #1

    Thread Starter
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560

    Question Loading Winamps m3u playlist to a ListBox question

    Was wondering if anyone had figured out how to load Winamp's m3u playlist to a listBox leaving out the # lines. I mean if you open up an m3u file you would or should normally see the lines containing file paths along with the #crap lines (like sample bellow). Well how would I go about populating a listBox I have with the lines containing file paths only and leave out all the lines starting with # ?
    I know I could probably loop through the listBox afterward and remove these unwanted lines but I was looking for a way to do this while I'm opening up the file for Input. Thanks a bunch.

    Here's a sample of an m3u playlist generated by Winamp.

    #EXTM3U
    #EXTINF:8,weezer - Living Without You
    D:\ftp\Full Albums (mp3)\weezer - Living Without You.mp3
    #EXTINF:227,01 - Razzmatazz
    D:\ftp\Full Albums (mp3)\Froggy Mix - No Nagging\01 - Razzmatazz.mp3
    #EXTINF:208,01 - Britney Spears - Sometimes (remix)
    D:\ftp\Full Albums (mp3)\Planet Pop 2000\01 - Britney Spears - Sometimes (remix).mp3
    #EXTINF:232,03 - Stay the night
    D:\ftp\Full Albums (mp3)\98 Degrees - Revelation\03 - Stay the night.mp3
    #EXTINF:234,03 - Could You Be Love
    D:\ftp\Full Albums (mp3)\Bob Marley - Legend\03 - Could You Be Love.mp3
    #EXTINF:196,06 - Get Up Stand Up
    D:\ftp\Full Albums (mp3)\Bob Marley - Legend\06 - Get Up Stand Up.mp3

    Here's a Sub I created to loads each lines into a listBox
    Problem is, well you know, it loads every lines
    VB Code:
    1. Public Sub LoadContents(ByVal List As ListBox, ByVal sFile As String)
    2.     Dim tmpString As String
    3.            
    4.     If Len(Dir(sFile)) Then ' Proceed only if file exists
    5.      
    6.       Open sFile For Input As #1
    7.        
    8.      Do Until EOF(1)
    9.        Line Input #1, tmpString
    10.        List.AddItem tmpString
    11.      Loop
    12.       Close #1
    13.    
    14.    End If
    15.        
    16. End Sub

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. Public Sub LoadContents(ByVal List As ListBox, ByVal sFile As String)
    2.     Dim tmpString As String
    3.            
    4.     If Len(Dir(sFile)) Then ' Proceed only if file exists
    5.      
    6.       Open sFile For Input As #1
    7.        
    8.      Do Until EOF(1)
    9.        Line Input #1, tmpString
    10.        List.AddItem replace(tmpString,"#","")
    11.      Loop
    12.       Close #1
    13.    
    14.    End If
    15.        
    16. End Sub

    Try that. (Froggy Mix - No Nagging) ???

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const HKEY_CLASSES_ROOT = &H80000000
    4.  
    5. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
    6.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType _
    7.   As Long, lpData As Any, lpcbData As Long) As Long
    8. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    9.   (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal _
    10.   samDesired As Long, phkResult As Long) As Long
    11. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    12.  
    13. Private Const WINAMP_REG_KEY = "WinAmp.File\shell\play\command"
    14. Private Const KEY_QUERY_VALUE = &H1
    15.  
    16. Public Sub LoadPlayList(LB As ListBox, PlayList As String)
    17.     Dim WholePlayList As String, Field As String
    18.     Dim sLines() As String, sFile() As String
    19.     Dim i As Integer
    20.    
    21.     Open PlayList For Input As #1
    22.     WholePlayList = Input(LOF(1), 1)
    23.     Close #1
    24.     WholePlayList = CorrectPlayList(WholePlayList)
    25.    
    26.     LB.Clear
    27.        
    28.     sLines = Split(WholePlayList, vbCrLf)
    29.     For i = 0 To UBound(sLines) - 1
    30.    
    31.         sLines(i) = Replace(sLines(i), Chr$(0), "")
    32.         sFile = Split(sLines(i), "%%%")
    33.         If UBound(sFile) = 0 Then
    34.             ReDim Preserve sFile(UBound(sFile) + 1)
    35.             sFile(1) = sFile(0)
    36.             sFile(0) = ""
    37.         End If
    38.        
    39.        
    40.         With LB
    41.             '.AddItem sFile(0)
    42.             If Mid$(sFile(1), 2, 1) = ":" Or Left$(sFile(1), 2) = "\\" Then
    43.                 'it includes the path of the file
    44.                 .AddItem sFile(1)
    45.             Else
    46.                 If Left$(sFile(1), 1) = "\" Then
    47.                     'It is on the same drive as the WinAmp
    48.                     Field = Left$(GetWinampPath, 2)
    49.                     .AddItem Field & sFile(1)
    50.                 Else
    51.                     'It is on the same path as the playlist
    52.                     .AddItem GetPath(PlayList) & sFile(1)
    53.                 End If
    54.             End If
    55.         End With
    56.        
    57.     Next i
    58. End Sub
    59.  
    60. Private Function GetWinampPath() As String
    61.     Dim A As Integer
    62.     GetWinampPath = GetWinampPathAndExeFile
    63.    
    64.     A = 1
    65.     Do While InStr(A + 1, GetWinampPath, "\")
    66.         A = A + 1
    67.     Loop
    68.     GetWinampPath = Left(GetWinampPath, A)
    69. End Function
    70.  
    71. Private Function GetWinampPathAndExeFile() As String
    72. 'Finds the path of winamp
    73.    
    74.     Dim WinampPath As String
    75.    
    76.     WinampPath = RegGetString(HKEY_CLASSES_ROOT, WINAMP_REG_KEY, "")
    77.     If Len(WinampPath) < 8 Then GetWinampPathAndExeFile = "": Exit Function
    78.     WinampPath = Mid(WinampPath, 2, Len(WinampPath) - 7)
    79.     GetWinampPathAndExeFile = WinampPath
    80. End Function
    81.  
    82. Private Function CorrectPlayList(All As String) As String
    83.     Dim ExtInf As Long, Enter As Long
    84.     Dim comma As Double
    85.     Dim sLines() As String
    86.     Dim i As Long, Last As Long
    87.    
    88.     All = Mid$(All, 10)
    89.     sLines = Split(All, vbCrLf)
    90.     Last = UBound(sLines) - 1
    91.     All = ""
    92.    
    93.     For i = 0 To Last
    94.         ExtInf = InStr(sLines(i), "#EXTINF")
    95.         If ExtInf Then
    96.             comma = InStr(ExtInf, sLines(i), ",")
    97.             sLines(i) = Mid$(sLines(i), comma + 1)
    98.             sLines(i) = sLines(i) & "%%%" & sLines(i + 1)
    99.             All = All & sLines(i) & vbCrLf
    100.             i = i + 1
    101.         Else
    102.             comma = InStr(UCase$(sLines(i)), ".MP")
    103.             sLines(i) = Left$(sLines(i), comma - 1) & "%%%" & sLines(i)
    104.             All = All & sLines(i) & vbCrLf
    105.         End If
    106.     Next i
    107.    
    108.     CorrectPlayList = All
    109. End Function
    110.  
    111. Private Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
    112.     Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, R As Long
    113.     RetVal$ = ""
    114.     R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_QUERY_VALUE, hSubKey)
    115.     If R <> 0 Then Exit Function
    116.     SZ = 256
    117.     v$ = String$(SZ, 0)
    118.     R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
    119.     If R = 0 And dwType = 1 Then
    120.         RetVal$ = Left(v$, SZ - 1)
    121.     Else
    122.         RetVal$ = ""
    123.     End If
    124.  
    125.  
    126.     If hInKey = 0 Then R = RegCloseKey(hSubKey)
    127.     RegGetString$ = RetVal$
    128. End Function
    129.  
    130. Private Function GetPath(Path As String) As String
    131.     Dim i As Integer
    132.     For i = Len(Path) To 1 Step -1
    133.         If Mid$(Path, i, 1) = "\" Then Exit For
    134.     Next i
    135.     GetPath = Left$(Path, i)
    136.  
    137. End Function
    138.  
    139.  
    140.  
    141.  
    142.  
    143. Private Sub Form_Load()
    144.     LoadPlayList List1, "C:\Downloaded Files\MP3\MP3.m3u"
    145. End Sub
    Last edited by Mc Brain; May 6th, 2002 at 03:56 AM.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Jesus Christ!!!

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    For more information, I found out that the #EXTINF-lines means this: The number besides the tag (and the colon) are the duration of the song in the seconds. And then, the artist and title (or whatever you've configured WinAmp)
    This is so that WinAmp can load quickly the list of song and its duration without "wasting" time opening each single song to get those data. This is why when you page-down, the duration is empty, and completed within some seconds.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6

    Thread Starter
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560

    GOOD GOD!!

    Holly smokes McBrain I'm sorry I ever went to bed last night! Have you been working on some kind of interface for Winamp?

    I'm using Winamp as the external mp3 player for my new Jukebox type app myself. I'm trying to get a commercial version happening. One that would use touch screen monitors and extra coin operated hardware. I did figure out a lot of winamps stuff myself searching all over the net this past 6 months but what you got there never once came across. Did you come up with that yourself.
    Anyway this is real nice stuff I owe you on this and also nice bit about the #EXTINF-lines I'll use this too, never thought of that either, thank you!

    BTW I had something that used the findwindow API aproached. You might have seen somethging like it around, although I found it to be to buggy to use as a permanent solution.
    VB Code:
    1. Public Function winampPlaylistToList(mvbListbox As Control) As Long
    2.     Dim lngJumpto As Long
    3.     Dim lngListBox As Long
    4.     Dim lngListIndex As Long
    5.     Dim strListitem As String * 256
    6.    
    7.     If lngWinamp = 0 Then Exit Function
    8.     PostMessage lngWinamp, 273, 40194, 0
    9.     Do
    10.         DoEvents
    11.         lngJumpto = FindWindow("#32770", "Jump to file")
    12.         lngListBox = FindWindowEx(lngJumpto, 0, "ListBox", vbNullString)
    13.     Loop Until lngListBox <> 0
    14.     DoEvents
    15.     On Error Resume Next
    16.     For lngListIndex = 0 To SendMessageLong(lngListBox, &H18B, 0, 0) - 1
    17.         Call SendMessageByString(lngListBox, &H189, lngListIndex, strListitem)
    18.      mvbListbox.AddItem strListitem
    19.      
    20.      Next lngListIndex
    21.     PostMessage lngJumpto, &H10, 0, 0
    22.     winampPlaylistToList = lngListIndex
    23. End Function
    Here is what I have accumulated in subs and functions that deals with winanp so far and I think I even got more kickin arround somewhere. I'm actually only using a few of them in my app.

    In no particullar order:
    WinampMinimized
    WinampMaximized
    winampToggleAlwaysOnTop
    WinampOnTop
    WinampClose
    winampExit
    WinAMP_SendCommandMessage
    WinAMP_SetVolume
    WinAMP_SetBalance
    WinAMP_GetTrackLength
    WinAMP_SeekToPosition
    WinAMP_GetTrackPosition
    winampPlaylistToList
    winampSetPlaylistPosition
    WinampClearPlaylist
    WinampHide
    winampSeekTime
    winampSetVolume
    winampReturnTrackLength_Full
    winampReturnTrackCurrentLength_Full
    winampReturnTrackLength_Seconds
    winampReturnTrackCurrent_Seconds
    winampWritePlaylist
    winampChannels
    winampBitRate
    winampSampleRate
    winampPlaylistPosition
    winampPlaylistCount
    winampVersion
    winampReloadCurrentSkin
    winampConfigureCurrentVisualizationPlugin
    winampOpenSkinSelector
    winampOpenJumpToFileDialog
    winampOpenJumpToTimeDialog
    winampToggleShuffle
    winampToggleRepeat
    winampLowerVolume
    winampRaiseVolume
    winampToggleEasyMove
    winampToggleMiniBrowser
    winampToggleMainWindow
    winampTogglePlaylist
    winampToggleEqualizer
    winampToggleDoubleSize
    winampTogglePlaylistWindowShade
    winampToggleWindowShade
    winampToggleTitleAutoScrolling
    winampToggleAboutBox
    winampVisualizationPlugin_Start_Stop
    winampVisualizationPluginOptions
    winampVisualizationOptions
    winampTogglePreferences
    winampTimeDisplayRemaining
    winampTimeDisplayElapsed
    winampOpenFileInfoBox
    winampOpenUrlDialog
    winampOpenFileDialog
    winampEndOfPlaylist
    winampStartOfPlaylist
    winampRewind5Seconds
    winampForward5Seconds
    winampStopAfterCurrentTrack
    winampFadeStop
    winampStop
    winampPause_Unpause
    winampPlay
    winampNext
    winampPrevious
    winampGetFileInfo
    winampOpenUrl
    winampMiniBrOpenUrl
    lngCountSongsByString
    winampJumpToFile
    winampJumpToTime
    winampSplitTitle
    IsWinampOnOff
    WinAMP_GetVersion
    winampPlaybackStatus

    Again thanks a lot !

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: GOOD GOD!!

    Originally posted by daydee
    Holly smokes McBrain I'm sorry I ever went to bed last night! Have you been working on some kind of interface for Winamp?
    I did!! Check the MP3 Organizer I created. I pasted some of the functions and subs I had and changed them a little to fit your needs. (My program uses a ListView, and have multiple columns... so part of the code was not needed for you).

    If you have more WinAmp-related questions, ask them here.... and send me a PM (Private Message) if you want me to read it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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