How could i get this LoadDir procedure to add all found Mp3's to the Playlist as i am not getting anything with this.
Code: Select all
ImportC "-framework CoreServices"
MDItemCreateWithURL(allocator, url)
MDItemCopyAttribute(item, name)
EndImport
; <<< Some constants from the NSFileManager class >>>
EnumerationBinary
#NSDirectoryEnumerationSkipsSubdirectoryDescendants
#NSDirectoryEnumerationSkipsPackageDescendants
#NSDirectoryEnumerationSkipsHiddenFiles
EndEnumeration
Enumeration PlayState
#stopped
#paused
#playing
EndEnumeration
Enumeration Ids
#WinMain
#ExpListG
#PlayList
#BackWard
#Play
#ForWard
#Stop
#Hide
#Pause
EndEnumeration
UsePNGImageDecoder()
NewList mp3list.s()
Global mp3Object
Global back0, play0, next0, stop0, hide0 ,pause0
Global kMDItemTitle.i = PeekI(dlsym_(-2, "kMDItemTitle"))
Global kMDItemDurationSeconds.i = PeekI(dlsym_(-2, "kMDItemDurationSeconds"))
Global Img_Window_0_0 = LoadImage(#PB_Any,"Resources/ys-play.png")
Global Img_Window_0_1 = LoadImage(#PB_Any,"Resources/ys-backward-3btns.png")
Global Img_Window_0_2 = LoadImage(#PB_Any,"Resources/ys-forward-3btns.png")
Global Img_Window_0_3 = LoadImage(#PB_Any,"Resources/ys-stop.png")
Global Img_Window_0_4 = LoadImage(#PB_Any,"Resources/ys-playlist-1btn.png")
Global Img_Window_0_5 = LoadImage(#PB_Any,"Resources/ys-playlist-1btn.png")
; <<< Open the main Window & setup Gadets >>>
Procedure OpenWindow_0(x = 0, y = 0, width = 815, height = 555)
OpenWindow(#WinMain, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_WindowCentered)
SetWindowColor(Window_0, RGB(213,213,213))
ExplorerListGadget(#ExpListG, 0, 0, 200, 520, GetHomeDirectory() + "Music/", #PB_Explorer_BorderLess | #PB_Explorer_AlwaysShowSelection)
ListIconGadget(#PlayList, 200, 20, 615, 500, "Title", 130, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#PlayList, 1, "Author", 130)
AddGadgetColumn(#PlayList, 2, "Duration", 130)
ImageGadget(#BackWard, 5, 525, 29, 23, ImageID(Img_Window_0_1))
GadgetToolTip(#BackWard, "Backward")
ImageGadget(#Play, 34, 525, 27, 23, ImageID(Img_Window_0_0))
GadgetToolTip(#Play, "Play/Pause")
ImageGadget(#ForWard, 60, 525, 29, 23, ImageID(Img_Window_0_2))
GadgetToolTip(#ForWard, "Forward")
ImageGadget(#Stop, 93, 525, 29, 23, ImageID(Img_Window_0_3))
GadgetToolTip(#Stop, "Stop")
ImageGadget(#Hide, 127, 525, 29, 23, ImageID(Img_Window_0_4))
GadgetToolTip(#Hide, "Show/Hide Playlits")
ProgressBar_0 = ProgressBarGadget(#PB_Any, 170, 530, 470, 15, 0, 0)
Container_0 = ContainerGadget(#PB_Any, 200, 0, 614, 20, #PB_Container_Flat)
SetGadgetColor(Container_0, #PB_Gadget_FrontColor,RGB(94,94,94))
CloseGadgetList()
AddWindowTimer(#WinMain, 0, 1000)
EndProcedure
; <<< Load mp3 file & play it >>>
Procedure LoadDir(Folder$)
Protected.i Pool, PathURL, FileArray, Mp3Array, Mp3Count, Mp3Item, Mp3MetaData, Attribute, i
Protected Mp3Path.s, Mp3Title.s, Mp3Duration.l
Pool = CocoaMessage(0, 0, "NSAutoreleasePool new")
PathURL = CocoaMessage(0,0, "NSURL fileURLWithPath:$", @Folder$)
If PathURL
FileArray = CocoaMessage(0, CocoaMessage(0, 0, "NSFileManager defaultManager"),
"contentsOfDirectoryAtURL:", PathURL,
"includingPropertiesForKeys:", 0, "options:", 4, "error:", 0)
If FileArray
; Get Mp3Array and Mp3Count
Mp3Array = CocoaMessage(0, FileArray, "filteredArrayUsingPredicate:",
CocoaMessage(0, 0, "NSPredicate predicateWithFormat:$",
@"pathExtension==[c]'mp3'", "argumentArray:", 0))
Mp3Count = CocoaMessage(0, Mp3Array, "count")
; Loop through all found Mp3 files
i = 0
While i < Mp3Count
Mp3Item = CocoaMessage(0, Mp3Array, "objectAtIndex:", i)
Mp3Path = PeekS(CocoaMessage(0, CocoaMessage(0, Mp3Item, "path"), "UTF8String"), -1, #PB_UTF8)
Mp3MetaData = MDItemCreateWithURL(0, Mp3Item)
; Get title
Mp3Title = ""
Attribute = MDItemCopyAttribute(Mp3MetaData, kMDItemTitle)
If Attribute
Mp3Title = PeekS(CocoaMessage(0, Attribute, "UTF8String"), -1, #PB_UTF8)
CFRelease_(Attribute)
EndIf
; Get duration
Mp3Duration = 0
Attribute = MDItemCopyAttribute(Mp3MetaData, kMDItemDurationSeconds)
If Attribute
Mp3Duration = CocoaMessage(0, Attribute, "intValue")
CFRelease_(Attribute)
EndIf
; Show the information about the mp3
;Debug "Path: " + Mp3Path
Debug "Title: " + Mp3Title
Debug "Duration :" + FormatDate("%hh:%ii:%ss", Mp3Duration)
CFRelease_(Mp3MetaData)
i + 1
Wend
EndIf
EndIf
CocoaMessage(0, Pool, "release")
EndProcedure
OpenWindow_0()
; <<< Start of main loop >>>
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #ExpListG
Select EventType()
Case #PB_EventType_LeftClick,#PB_EventType_LeftDoubleClick
LoadDir(GetGadgetText(#ExpListG)) ; << possible problem not sure <<
EndSelect
EndSelect
EndSelect
Until Quit
End