Try it on your own risk I won't be responsible. Continue reading if it didn't work for you.
First hold the up or down volume and try cleaning out the dust,lint,dirt,etc with a toothpick or a needle then use a toothbrush to clean out the charging port then try pressing from the top of the charging port down until you can see the volume bar back and stop when you see it and play music or a video. if this didnt work replace your charging port.
one of my customer has an iphone that his music wouldn't come out of the speakers but the ringtones works in this situation the issue its that the charging port its malfunction. in this video im showing that im bending the pins down to bring the volume bar back and this means the charging port its dirty or has liquid damage or it was pull hard from charging it.
the fix its simple replace the charging port if this didn't work for you.