I have a Panasonic TV with 3 HDMI ports. To my media player 401 (Telekom) and a Ps4 are connected. I also have a soundbar (Samsung HW-K550 / EN 3.1 Soundbar).
I can't get these three things together in any way, so the soundbar works on every device. Currently I have an optical cable between Media Player and Soundbar, Ps4 does not work at all.
If the soundbar has HDMI:
TV with ARC (standing next to one of the HDMI ports): Connect Soundbar with HDMI to this port. Enable ARC and Anynet + (HDMI CEC) on both devices, if not done by itself.
TV without ARC: buy an HDMI switch and attach both
If Soundbar does not have HDMI:
Your TV pretty much has an optical output, just hang cables.
For a soundbar, it does not matter if it's HDMI or optical. For a surround system HDMI should be preferred.