How to do audio output selection for MediaPlayer control?

Post your Gambas programming questions here.
GrantXTV
Posts: 17
Joined: Tuesday 31st October 2023 9:20pm

Re: How to do audio output selection for MediaPlayer control?

Post by GrantXTV »

Hi Vuott,

I reworked the code for the UDP Receiver and that seemed to get it to work okay, there is one small issue with the UDP Transmitter, but it works well enough.

Here is the Transmitter:

Public bo As Boolean
Public pl As MediaPipeline

Public Sub Form_Open()
bo = True
End

Public Sub send_Click()

Dim src, aco, wen, snk, rtp, udp As MediaControl
Dim flt As MediaFilter

bo = True
pl = New MediaPipeline

src = New MediaControl(pl, "alsasrc")
aco = New MediaControl(pl, "audioconvert")
flt = New MediaFilter(pl, "audio/x-raw,rate=41000,depth=8,channels=2,signed=true")
rtp = New MediaControl(pl, "rtpL24pay")
udp = New MediaControl(pl, "udpsink")
udp["host"] = "192.168.3.15"
udp["port"] = "5004"

src.LinkTo(aco)
aco.LinkTo(flt)
flt.LinkTo(rtp)
rtp.LinkTo(udp)

pl.Play()
While bo
TextBox1.Text = Str(Time(0, 0, 0, pl.Position * 1000))
Wait 0.01
Wend
End

Public Sub stop_Click()
pl.Stop()
bo = False
End

Public Sub Form_Close()
pl.Stop()
pl.Close()
bo = False
End

Here is what works for the Receiver:

Public bo As Boolean
Public pl As MediaPipeline

Public Sub Form_Open()

Dim src, rtp, aco, als As MediaControl
Dim flt As MediaFilter

pl = New MediaPipeline
src = New MediaControl(pl, "udpsrc")
src["port"] = "5004"
flt = New MediaFilter(pl, "application/x-rtp,media=audio,payload=96,clock-rate=41000,depth=8,channels=2,signed=true,encoding-name=L24")
rtp = New MediaControl(pl, "rtpL24depay")
aco = New MediaControl(pl, "audioconvert")
als = New MediaControl(pl, "autoaudiosink")
als["sync"] = "false"

src.LinkTo(flt)
flt.LinkTo(rtp)
rtp.LinkTo(aco)
aco.LinkTo(als)
pl.Pause
End

Public Sub Play_Click()
pl.Play()
bo = True
While bo
TextBox1.Text = Str(Time(0, 0, 0, pl.Position * 1000))
Wait 0.01
Wend
End

Public Sub stop_Click()
pl.Pause()
pl.Stop()
bo = False
End

Public Sub Form_Close()
pl.Stop()
pl.Close()
bo = False
End

With the UDP receiver I found that I needed to use a work around by using pause then stop, or the the software could crash.

From this experimenting, I workout that the the MediaPlayer has four input / output states:
Hardware
File
IP / UDP
Jack Audio

The Jack Audio is something I may look at as well, at later date as could be useful, but the IP streaming is important one right now.
Post Reply