<div dir="ltr">Hi, I have tried your code but I am getting "Null Object" error at runtime at line "audio.play(sample)", after selecting file in Dialog.OpenFile().<div>Fmain.close works.</div><div>Thx<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mar 3 mag 2022 alle ore 17:46 T Lee Davidson <<a href="mailto:t.lee.davidson@gmail.com">t.lee.davidson@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 5/3/22 08:28, Charles Bukowski wrote:<br>
> Hello, I am writing a simple application that plays a self made .wav file using sdl2.<br>
> 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 <br>
> and go back to main and the other to close the application.It works, but the sample is played for eight (???) times only; <br>
> clicking on the button for the ninth time and further, sound channel is muted.<br>
<br>
> Furthermore, Is it possible to declare event handlers of the second form private?<br>
<br>
No. Event handlers must be Public methods so the event loop manager can "see" them.<br>
See <a href="http://gambaswiki.org/wiki/doc/object-model#t7" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/doc/object-model#t7</a><br>
<br>
<br>
Attempting to play the sound file for the ninth time, the sound is not muted. It simply does not play.<br>
<br>
It appears that creating and destroying the Channel multiple times causes a resource lock. It should not be necessary to <br>
re-create the Channel every time a WAV file is to be played. It can be created once when the form is opened.<br>
<br>
Try this code:<br>
[code]<br>
' Gambas class file<br>
<br>
Private audio As Channel<br>
<br>
Public Sub Form_Open()<br>
  audio = New Channel As "audio"<br>
End<br>
<br>
Private Sub PlayAudio()<br>
 Dim sample As Sound<br>
 Dim Filename As String<br>
<br>
 Dialog.Filter = ["*.wav;*.mp3", "audio files"]<br>
 Dialog.Path = Application.Path<br>
 If Dialog.OpenFile() Then Return 'User clicked cancel. No selection, back to calling form.<br>
 Filename = Dialog.Path<br>
<br>
 sample = Sound.load(Filename)<br>
 audio.play(sample)<br>
 sample = Null 'destoy sound object<br>
End<br>
[/code]<br>
<br>
BTW, Quit should not be used to close a graphical application. Your QuitProgram button click event handler should be:<br>
<br>
Public Sub QuitProgram_Click()<br>
  TestAudioPlay.Close<br>
  FMain.Close<br>
End<br>
<br>
<br>
HTH.<br>
<br>
<br>
-- <br>
Lee<br>
<br>
----[ <a href="http://gambaswiki.org/wiki/doc/netiquette" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/doc/netiquette</a> ]----<br>
</blockquote></div>