[Gambas-user] sdl2 application

Charles Bukowski charlesbukowski.italy at gmail.com
Tue May 3 21:15:07 CEST 2022


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().
Fmain.close works.
Thx

Il giorno mar 3 mag 2022 alle ore 17:46 T Lee Davidson <
t.lee.davidson at gmail.com> ha scritto:

> 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
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220503/42901ea0/attachment.htm>


More information about the User mailing list