|
-
May 6th, 2002, 03:20 AM
#1
Thread Starter
Fanatic Member
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:
Public Sub LoadContents(ByVal List As ListBox, ByVal sFile As String)
Dim tmpString As String
If Len(Dir(sFile)) Then ' Proceed only if file exists
Open sFile For Input As #1
Do Until EOF(1)
Line Input #1, tmpString
List.AddItem tmpString
Loop
Close #1
End If
End Sub
-
May 6th, 2002, 03:26 AM
#2
VB Code:
Public Sub LoadContents(ByVal List As ListBox, ByVal sFile As String)
Dim tmpString As String
If Len(Dir(sFile)) Then ' Proceed only if file exists
Open sFile For Input As #1
Do Until EOF(1)
Line Input #1, tmpString
List.AddItem replace(tmpString,"#","")
Loop
Close #1
End If
End Sub
Try that. (Froggy Mix - No Nagging) ???
-
May 6th, 2002, 03:52 AM
#3
Need-a-life Member
VB Code:
Option Explicit
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType _
As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal _
samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const WINAMP_REG_KEY = "WinAmp.File\shell\play\command"
Private Const KEY_QUERY_VALUE = &H1
Public Sub LoadPlayList(LB As ListBox, PlayList As String)
Dim WholePlayList As String, Field As String
Dim sLines() As String, sFile() As String
Dim i As Integer
Open PlayList For Input As #1
WholePlayList = Input(LOF(1), 1)
Close #1
WholePlayList = CorrectPlayList(WholePlayList)
LB.Clear
sLines = Split(WholePlayList, vbCrLf)
For i = 0 To UBound(sLines) - 1
sLines(i) = Replace(sLines(i), Chr$(0), "")
sFile = Split(sLines(i), "%%%")
If UBound(sFile) = 0 Then
ReDim Preserve sFile(UBound(sFile) + 1)
sFile(1) = sFile(0)
sFile(0) = ""
End If
With LB
'.AddItem sFile(0)
If Mid$(sFile(1), 2, 1) = ":" Or Left$(sFile(1), 2) = "\\" Then
'it includes the path of the file
.AddItem sFile(1)
Else
If Left$(sFile(1), 1) = "\" Then
'It is on the same drive as the WinAmp
Field = Left$(GetWinampPath, 2)
.AddItem Field & sFile(1)
Else
'It is on the same path as the playlist
.AddItem GetPath(PlayList) & sFile(1)
End If
End If
End With
Next i
End Sub
Private Function GetWinampPath() As String
Dim A As Integer
GetWinampPath = GetWinampPathAndExeFile
A = 1
Do While InStr(A + 1, GetWinampPath, "\")
A = A + 1
Loop
GetWinampPath = Left(GetWinampPath, A)
End Function
Private Function GetWinampPathAndExeFile() As String
'Finds the path of winamp
Dim WinampPath As String
WinampPath = RegGetString(HKEY_CLASSES_ROOT, WINAMP_REG_KEY, "")
If Len(WinampPath) < 8 Then GetWinampPathAndExeFile = "": Exit Function
WinampPath = Mid(WinampPath, 2, Len(WinampPath) - 7)
GetWinampPathAndExeFile = WinampPath
End Function
Private Function CorrectPlayList(All As String) As String
Dim ExtInf As Long, Enter As Long
Dim comma As Double
Dim sLines() As String
Dim i As Long, Last As Long
All = Mid$(All, 10)
sLines = Split(All, vbCrLf)
Last = UBound(sLines) - 1
All = ""
For i = 0 To Last
ExtInf = InStr(sLines(i), "#EXTINF")
If ExtInf Then
comma = InStr(ExtInf, sLines(i), ",")
sLines(i) = Mid$(sLines(i), comma + 1)
sLines(i) = sLines(i) & "%%%" & sLines(i + 1)
All = All & sLines(i) & vbCrLf
i = i + 1
Else
comma = InStr(UCase$(sLines(i)), ".MP")
sLines(i) = Left$(sLines(i), comma - 1) & "%%%" & sLines(i)
All = All & sLines(i) & vbCrLf
End If
Next i
CorrectPlayList = All
End Function
Private Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, R As Long
RetVal$ = ""
R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_QUERY_VALUE, hSubKey)
If R <> 0 Then Exit Function
SZ = 256
v$ = String$(SZ, 0)
R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
If R = 0 And dwType = 1 Then
RetVal$ = Left(v$, SZ - 1)
Else
RetVal$ = ""
End If
If hInKey = 0 Then R = RegCloseKey(hSubKey)
RegGetString$ = RetVal$
End Function
Private Function GetPath(Path As String) As String
Dim i As Integer
For i = Len(Path) To 1 Step -1
If Mid$(Path, i, 1) = "\" Then Exit For
Next i
GetPath = Left$(Path, i)
End Function
Private Sub Form_Load()
LoadPlayList List1, "C:\Downloaded Files\MP3\MP3.m3u"
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.
-
May 6th, 2002, 03:55 AM
#4
Jesus Christ!!!
-
May 6th, 2002, 04:02 AM
#5
-
May 6th, 2002, 11:54 AM
#6
Thread Starter
Fanatic Member
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:
Public Function winampPlaylistToList(mvbListbox As Control) As Long
Dim lngJumpto As Long
Dim lngListBox As Long
Dim lngListIndex As Long
Dim strListitem As String * 256
If lngWinamp = 0 Then Exit Function
PostMessage lngWinamp, 273, 40194, 0
Do
DoEvents
lngJumpto = FindWindow("#32770", "Jump to file")
lngListBox = FindWindowEx(lngJumpto, 0, "ListBox", vbNullString)
Loop Until lngListBox <> 0
DoEvents
On Error Resume Next
For lngListIndex = 0 To SendMessageLong(lngListBox, &H18B, 0, 0) - 1
Call SendMessageByString(lngListBox, &H189, lngListIndex, strListitem)
mvbListbox.AddItem strListitem
Next lngListIndex
PostMessage lngJumpto, &H10, 0, 0
winampPlaylistToList = lngListIndex
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 !
-
May 6th, 2002, 04:01 PM
#7
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
|