Completely disable audio jack as a media output
https://plus.google.com/100255718384858554176/posts/Bqp8GtkQY9x Mr Ian Grody had posted a solution to be done by tasker and Lesser audio manager.

Edit for in case the link was changed.

You need to send Lesser AudioSwitch intents and it'll switch between headphones and speaker..
By Tasker.

LAIH (232)
    A1: Send Intent [ Action:com.nordskog.LesserAudioSwitch.HEADPHONES Cat:None Mime Type: Data: Extra: Extra: Extra: Package:com.nordskog.LesserAudioSwitch Class:com.nordskog.LesserAudioSwitch.SoundBroadcastReceiver Target:Broadcast Receiver ] 

LAIS (233)
    A1: Send Intent [ Action:com.nordskog.LesserAudioSwitch.SPEAKER Cat:None Mime Type: Data: Extra: Extra: Extra: Package:com.nordskog.LesserAudioSwitch Class:com.nordskog.LesserAudioSwitch.SoundBroadcastReceiver Target:Broadcast Receiver ] 
Edited for