So Confused (SOLVED)
Posted: Wed Jul 12, 2017 1:08 pm
Hi having spent hours trying to rewrite this code so i can load all selected files to play with no luck
wondering if any one can point me in the right direction as i am now so confused with all the changes
I have tried using an array and recursing the selected folder but does not work.
thanks for any help at all.
wondering if any one can point me in the right direction as i am now so confused with all the changes
I have tried using an array and recursing the selected folder but does not work.
thanks for any help at all.
Code: Select all
Enumeration playState
#stopped
#paused
#playing
EndEnumeration
NewList mp3list.s()
Global mp3Object
Procedure LoadMp3(File$)
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
mp3Object = CocoaMessage(0, CocoaMessage(0, 0, "NSSound alloc"), "initWithContentsOfFile:$", @File$, "byReference:", #YES)
CocoaMessage(0, mp3Object, "play")
CompilerElse
mp3Object = LoadSound(#PB_Any, File$)
PlaySound(mp3Object)
CompilerEndIf
EndProcedure
#FLAGS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered
CompilerIf #PB_Compiler_OS <> #PB_OS_MacOS
InitSound()
CompilerEndIf
mainWin = OpenWindow(#PB_Any, 0, 0, 800, 380, "MP3 Player 0.1", #FLAGS)
SetWindowColor(mainWin, RGB(0,83,146))
AddWindowTimer(mainWin, 0, 1000)
loadBtn = ButtonGadget(#PB_Any, 20, 350, 100, 25, "Add")
stopBtn = ButtonGadget(#PB_Any, 130, 350, 100, 25, "Stop")
playBtn = ButtonGadget(#PB_Any, 240, 350, 100, 25, "Play")
pauseBtn = ButtonGadget(#PB_Any, 350, 350, 100, 25, "Pause")
exitBtn = ButtonGadget(#PB_Any, 460, 350, 100, 25, "Exit")
playlist = ListIconGadget(#PB_Any, 30, 10, 740, 300, "Song Title", 150, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(playlist, 1, "Size", 130)
AddGadgetColumn(playlist, 2, "Duration", 130)
AddGadgetColumn(playlist, 3, "Elapsed", 130)
;DisableGadget(playBtn, #True)
;DisableGadget(stopBtn, #True)
;DisableGadget(pauseBtn, #True)
; Start of main loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Timer
If mp3Object
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
If Not CocoaMessage(0, mp3Object, "isPlaying")
CompilerElse
If Not SoundStatus(mp3Object) = #PB_Sound_Playing
CompilerEndIf
If state = #playing
If Not NextElement(mp3list())
FirstElement(mp3list())
EndIf
LoadMp3(mp3list())
SetGadgetState(playlist, CompilerElseex(mp3list()))
EndIf
EndIf
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case loadBtn
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
mp3File$ = OpenFileRequester("Select MP3 Track:", "", "MP3|*.mp3", 0)
CompilerElse
mp3File$ = OpenFileRequester("Select WAV Track:", "", "WAV|*.wav", 0)
CompilerEndIf
If mp3File$ <> ""
AddGadgetItem(playlist, -1, GetFilePart(mp3File$, #PB_FileSystem_NoExtension))
SetGadgetItemText(playlist, ListSize(mp3list()), FormatNumber(FileSize(mp3File$)) + " bytes", 1)
; get the duration time and release
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
mp3Obj = CocoaMessage(0, CocoaMessage(0, 0, "NSSound alloc"), "initWithContentsOfFile:$", @mp3File$, "byReference:", #YES)
CocoaMessage(@duration.d, mp3Obj, "duration")
CocoaMessage(0, mp3Obj, "release")
CompilerEndIf
; now we publish the duration in the list
SetGadgetItemText(playlist, ListSize(mp3list()), FormatDate("%hh:%ii:%ss", duration), 2)
AddElement(mp3list())
mp3list() = mp3File$
If ListSize(mp3list()) = 1
SetGadgetState(playlist, 0)
;DisableGadget(playBtn, #True)
;DisableGadget(stopBtn, #True)
;DisableGadget(pauseBtn, #True)
EndIf
EndIf
Case exitBtn
Quit = #True
Case stopBtn
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(0, mp3Object, "stop")
CompilerElse
StopSound(mp3Object)
CompilerEndIf
state = #stopped
;DisableGadget(stopBtn, #True)
;DisableGadget(loadBtn, #False)
;DisableGadget(pauseBtn, #True)
;DisableGadget(playBtn, #False)
Case playBtn
Select state
Case #stopped
state = #playing
SelectElement(mp3list(), GetGadgetState(playlist))
LoadMp3(mp3list())
;DisableGadget(stopBtn, #False)
;DisableGadget(pauseBtn, #False)
;DisableGadget(playBtn, #True)
EndSelect
Case pauseBtn
Select state
Case #paused
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(0, mp3Object, "resume")
CompilerElse
ResumeSound(mp3Object)
CompilerEndIf
state = #playing
Case #playing
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(0, mp3Object, "pause")
CompilerElse
PauseSound(mp3Object)
CompilerEndIf
state = #paused
EndSelect
Case playlist
If CountGadgetItems(playlist) > 0
Select EventType()
Case #PB_EventType_LeftClick
;DisableGadget(playBtn, #False) : DisableGadget(stopBtn, #True)
;DisableGadget(loadBtn, #True) : DisableGadget(pauseBtn, #True)
EndSelect
EndIf
EndSelect
EndSelect
Until Quit
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(0, mp3Object, "stop")
CocoaMessage(0, mp3Object, "release")
CompilerElse
If IsSound(mp3Object)
If SoundStatus(mp3Object, #PB_Sound_Playing)
StopSound(mp3Object)
EndIf
FreeSound(mp3Object)
EndIf
CompilerEndIf