Oh, with thanks to wilbert for the Cocoa code.
...and be sure to look at wilberts code for playing a sound file here https://www.purebasic.fr/english/viewto ... 31#p392931
Code: Select all
EnableExplicit
ExamineDesktops()
#showfileswnd=1
#showfilesefid=1
Global Dim SoundName.s(15) ; one extra for 'End'
Define event ; for loop only
Define err,cnt,filename$ ; don't need to be globals
Global maxsounds ; not needed unless you want to list sounds (shouldn't need to)
DataSection
SoundData:
Data.s "Basso.aiff","Blow.aiff","Bottle.aiff","Frog.aiff","Funk.aiff","Glass.aiff",
"Hero.aiff","Morse.aiff","Ping.aiff","Pop.aiff","Purr.aiff","Sosumi.aiff","Submarine.aiff",
"Tink.aiff","End"
EndDataSection
Enumeration 1
#sndsave
#sndtink
#sndclick
#snderror
EndEnumeration
Restore SoundData : cnt=1 : Read.s filename$ : maxsounds=0
While filename$<>"End"
maxsounds+1
err=CocoaMessage(0, 0, "NSSound soundNamed:$", @filename$)
If err=0
MessageRequester("Loading sounds...",filename$+" was not loaded")
Else
SoundName(cnt)=filename$
EndIf
cnt+1
Read.s filename$
Wend
Procedure Speak(snd)
Define err
If SoundName(snd)<>"" ; not needed
err=CocoaMessage(0, 0, "NSSound soundNamed:$", @SoundName(snd))
CocoaMessage(0,err, "play") ;: Delay(2000)
EndIf
EndProcedure
Procedure ShowFiles()
Define w=200,h=maxsounds*20
If h>DesktopHeight(0)-55 : h=DesktopHeight(0)-55 : EndIf
Define cnt,xtab,ytab,fw,lh=25
If OpenWindow(#ShowFilesWnd,0,0,w,h,"List of files",#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ListViewGadget(#showfilesefid,0,0,WindowWidth(#ShowFilesWnd),WindowHeight(#ShowFilesWnd))
For cnt=1 To maxsounds
AddGadgetItem(#showfilesefid,-1,Str(cnt)+". "+SoundName(cnt))
Next
EndIf
EndProcedure
Procedure DoShowFiles(event)
Define id,event
Select event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
id=EventGadget()
Select id
Case #showfilesefid ; click on listview
If EventType()=#PB_EventType_LeftClick
Speak(GetGadgetState(#showfilesefid)+1)
EndIf
EndSelect
EndSelect
EndProcedure
ShowFiles()
Repeat
event = WaitWindowEvent()
Select EventWindow()
Case #showfileswnd
DoShowFiles(event)
EndSelect
ForEver