[Gambas-user] Play tracks with gb.Media (Gstreamer)

Claus Dietrich claus.dietrich at freenet.de
Mon Jan 15 18:16:10 CET 2024


Am 15.01.24 um 13:07 schrieb System64 Development:
> Hi,
>
> I want to play 2 tracks at the same time wit the "MediaPipeline" class.
>
> Claus solve the problem for internet streams using a "MediaContainer" 
> class but I cant do it for 2 local media files, such mp3, ogg, aac etc.
>
> Then I mod the sample (see attachment) from gambas-it.org/wiki [1] but 
> doesn't  work.
>
> So I share this little project if you want to test it.
>
> Note: I wan to do more things in the near future, such manage the 
> volume independently for each file or mute some of them, join all the 
> tracks in one file.
>
> [1] 
> https://www.gambas-it.org/wiki/index.php/Eseguire_due_o_pi%C3%B9_file_audio_contemporaneamente_mediante_la_Classe_%27%27MediaPipeline%27%27_del_componente_gb.media
>
> Thanks.
>
> Martin

I adapted the MediaContainer-sample I sent to you and it worked on the spot:

Private pl As MediaPipeline
Private cPlayParallel As MediaContainer
Private src1 As MediaControl
Private prs1 As MediaControl
Private dec1 As MediaControl
Private cnv1 As MediaControl
Private rsp1 As MediaControl
Private snk1 As MediaControl

Private src2 As MediaControl
Private prs2 As MediaControl
Private dec2 As MediaControl
Private cnv2 As MediaControl
Private rsp2 As MediaControl
Private snk2 As MediaControl

Public Sub Form_Open()

   pl = New MediaPipeline As "PipeEvents"
   cPlayParallel = New MediaContainer(pl)

   src1 = New MediaControl(cPlayParallel, "filesrc")
   src1["location"] = "/home/claus/Musik/song1.mp3"
   prs1 = New MediaControl(cPlayParallel, "mpegaudioparse")
   dec1 = New MediaControl(cPlayParallel, "mpg123audiodec")
   cnv1 = New MediaControl(cPlayParallel, "audioconvert")
   rsp1 = New MediaControl(cPlayParallel, "audioresample")
   snk1 = New MediaControl(cPlayParallel, "autoaudiosink")
   src1.LinkTo(prs1)
   prs1.LinkTo(dec1)
   dec1.LinkTo(cnv1)
   cnv1.Linkto(rsp1)
   rsp1.LinkTo(snk1)

   src2 = New MediaControl(cPlayParallel, "filesrc")
   src2["location"] = "/home/claus/Musik/song2.mp3"
   prs2 = New MediaControl(cPlayParallel, "mpegaudioparse")
   dec2 = New MediaControl(cPlayParallel, "mpg123audiodec")
   cnv2 = New MediaControl(cPlayParallel, "audioconvert")
   rsp2 = New MediaControl(cPlayParallel, "audioresample")
   snk2 = New MediaControl(cPlayParallel, "autoaudiosink")
   src2.LinkTo(prs2)
   prs2.LinkTo(dec2)
   dec2.LinkTo(cnv2)
   cnv2.Linkto(rsp2)
   rsp2.LinkTo(snk2)

   pl.play

End

Audio level control can be added for each branch independently.

Best regards

Claus




More information about the User mailing list