[Gambas-user] gb.media - Pipelines with local declarations don't work

Benoît Minisini benoit.minisini at gambas-basic.org
Mon Jan 15 20:28:11 CET 2024


Le 15/01/2024 à 13:59, Claus Dietrich a écrit :
> Am 15.01.24 um 11:56 schrieb Benoît Minisini:
>> Le 15/01/2024 à 10:34, Claus Dietrich a écrit :
>>> I found that gb.media-pipelines with local declarations don't work on 
>>> V3.18.4 and the master. Here an example which doesn't show any error 
>>> but doesn't produce the expected default 440 Hz output tone:
>>>
>>> Public Sub Form_Open()
>>>
>>>    Dim pl As MediaPipeline
>>>    Dim src As MediaControl
>>>    Dim cnv As MediaControl
>>>    Dim snk As MediaControl
>>>
>>>    pl = New MediaPipeline
>>>    src = New MediaControl(pl, "audiotestsrc")
>>>    cnv = New MediaControl(pl, "audioconvert")
>>>    snk = New MediaControl(pl, "autoaudiosink")
>>>
>>>    src.LinkTo(cnv)
>>>    cnv.LinkTo(snk)
>>>
>>>    pl.play
>>>
>>> End
>>>
>>
>> If you don't keep a reference on a MediaControl, it is destroyed.
>>
>> This is what happened once pl.play() is called and the function exits: 
>> all your control are destroyed.
>>
>> Just add WAIT 5 after pl.play() to understand.
> 
> Thanks! The penny dropped after "WAIT 5".
> 
> Best regards
> 
> Claus
> 

In the last commit, Parents MediaControl (i.e. MediaContainer) 
automatically reference and derefence their children.

So now you just have to store the top-level MediaControl (the 
MediaPipeliine in your example) in a global variable to keep everything 
around.

Regard,

-- 
Benoît Minisini.



More information about the User mailing list