Use system sounds in place of PlayMovies

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Use system sounds in place of PlayMovies

Post by WilliamL »

Maybe you could use some of my ideas here.

Oh, with thanks to wilbert for the Cocoa code. :D

...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
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1