First, restart your phone. Re-install the playing music app.
Then try to insert your headphones into the headphone jack then take them out. Continue to do this for a couple of minutes as sometimes the phone tricks its self into thinking its in headphone mode. Also by doing this step you are likely to dislodge any dust or dirt build up that also may be causing this issue.
Last, if all failed, it must be the hardware problem. Replace with an original [http://www.witrigs.com/replacement-parts-headphone-jack-for-samsung-galaxy-s4-gt-i9505-oem|headphone jack.]
Good luck to you!