[Gambas-user] sdl2 application
T Lee Davidson
t.lee.davidson at gmail.com
Tue May 3 17:45:53 CEST 2022
On 5/3/22 08:28, Charles Bukowski wrote:
> Hello, I am writing a simple application that plays a self made .wav file using sdl2.
> It is a main form with a button that opens another form with three buttons : one to choose the file to play, one to close form
> and go back to main and the other to close the application.It works, but the sample is played for eight (???) times only;
> clicking on the button for the ninth time and further, sound channel is muted.
> Furthermore, Is it possible to declare event handlers of the second form private?
No. Event handlers must be Public methods so the event loop manager can "see" them.
See http://gambaswiki.org/wiki/doc/object-model#t7
Attempting to play the sound file for the ninth time, the sound is not muted. It simply does not play.
It appears that creating and destroying the Channel multiple times causes a resource lock. It should not be necessary to
re-create the Channel every time a WAV file is to be played. It can be created once when the form is opened.
Try this code:
[code]
' Gambas class file
Private audio As Channel
Public Sub Form_Open()
audio = New Channel As "audio"
End
Private Sub PlayAudio()
Dim sample As Sound
Dim Filename As String
Dialog.Filter = ["*.wav;*.mp3", "audio files"]
Dialog.Path = Application.Path
If Dialog.OpenFile() Then Return 'User clicked cancel. No selection, back to calling form.
Filename = Dialog.Path
sample = Sound.load(Filename)
audio.play(sample)
sample = Null 'destoy sound object
End
[/code]
BTW, Quit should not be used to close a graphical application. Your QuitProgram button click event handler should be:
Public Sub QuitProgram_Click()
TestAudioPlay.Close
FMain.Close
End
HTH.
--
Lee
More information about the User
mailing list