how to play music in speaker when headset is connected

Solution
You might be able to do it through Bluetooth with a suitable speaker but the headset socket is set to cut the phone's own speaker as soon as it's put to use.
Although it may not be possible to do what you are trying to do, you could also get a 3.5mm splitter and connect your headset AND another speaker to it. Is this iOS or Android (or something else)?