I use the optical output on my motherboard and the area between the connector and the cable is loose.
When the cable moves, the sound stops.
It could be the cable but have you ever heard of this problem?
Swap ends of the cable. That'll tell you if it's the cable or not. The good news is that optical cables, especially the cheap ones, are light enough so once it works in position you can use any type to putty (picture mounting putty, silly putty, MoreTite) to fix it in place.
Had the same problem a while back on a old Logitech Z-5500 I used 2 to 3 turns of some thin teflon tape around the plug to tighten it up and then used a tie back to hold it in place and it is still working.