I’m a beginner in GStreamer, and I want to play multiple audio files simultaneously, using the same audio sink. I would like to be able to control each audio file individually, such as play and pause. How should I approach this? Do I need to create multiple pipelines to handle each audio file separately? I tried this approach, but using the same sink for multiple audio files caused conflicts. I also attempted to create multiple sub-bins within a single pipeline to control each audio file individually, but the sub-bins’ states seem to be controlled by the parent pipeline, making it ineffective to set one bin to the paused state. Are there any other methods to achieve my goal? I would greatly appreciate any advice. Thank you in advance.
If you want to control them independently, you want to use multiple pipelines. To share the audio hardware, the best approach is to use something like PipeWire (if you’re on Linux), so you can do it entirely outside of GStreamer. Otherwise, you can use something like proxysink/proxysrc to connect the player pipelines to the sink pipeline, but that’s more tricky to get right.
What are your synchronisation requirements?
Something like this might work:
Mixer pipeline:
audiomixer name=mix ! audio/x-raw,rate=48000 ! someaudiosink
interaudiosink channel=stream-1 ! audioresample ! mix.
interaudiosink channel=stream-2 ! audioresample ! mix.
Input pipeline 1 (play/pause/seek at your leisure)
playbin3 audio-sink="interaudiosink channel=stream-1
Input pipeline 2 (play/pause/seek at your leisure)
playbin3 audio-sink="interaudiosink channel=stream-2
However, it will be tricky to maintain lipsync using this particular mechanism, in case that’s important.
as Olivier said, it’s probably better to let the audio server/stack do this directly.
You can also just do (e.g.)
Input pipeline 1 (play/pause/seek at your leisure)
playbin3 audio-sink=pulsesink
Input pipeline 2 (play/pause/seek at your leisure)
playbin3 audio-sink=pulsesink
and then pulseaudio (for example) will just do the mixing.