Soundbars work by either taking an audio feed directly from a source (typically with optical) or by using an Audio-Return-Channel from the TV. This requires the TV have ARC capability AND that you plug the cable into that port on the TV.
There have been some TVs that have an optical OUT that can be plugged FROM the TV into a soundbar. But not all TVs have this, and it's not without other complications.
So, start with what model TV do you have and does it have either an optical or an HDMI-ARC feature. If it doesn't then get a new TV that does, one that's known to work. Because there are no reliable work-arounds, other than to use an AVR to handle the sound and source switching.
So I have a Samsung Q6 and it does have ARC. Unfortunately my current soundbar is a Polk that lacks HDMI input so ARC is useless at the moment. In addition I hear Samsung lacks support of DTS in 2019