Glam Prestige Journal

Bright entertainment trends with youth appeal.

I'm asking for any solution (algorithm, program installation ...) to get music stopping when we remove headphones,

Thank you !

2 Answers

It happens by default , as ubuntu 14.04 have different profiles for your headphone and your speaker. Just mute your speaker first and then insert your headphones, it will activate headphone profile and you can listen music, the moment you remove your headphone it will go back to speaker profile which was initially muted, so it will be muted.

Actually, it has a 1sec delay. As I couldn't find any system event that triggered with the remove of headphones plug, so I used 1sec delay loop.

  1. Check for sink ID and port names using:

    pactl list sinks
  2. Then change them in this script that monitor port state then send MPRIS pause command:

    #!/bin/bash
    sink_id=1
    port_name_headset=analog-output-headphones
    port_name_speaker=analog-output-speaker
    while sleep 1 ;
    do cur_port=`pactl list sinks | awk '/Active Port:/ { print $3 }' | awk NR==$(( $sink_id + 1 ))` echo -n -e "\n was $prev_port now $cur_port" if [[ "$prev_port" = "$port_name_headset" && "$cur_port" = "$port_name_speaker" ]] then echo " << Pause >>" gdbus call --session \ --dest org.mpris.MediaPlayer2.vlc.instance$(pgrep vlc) \ --object-path /org/mpris/MediaPlayer2 \ --method org.mpris.MediaPlayer2.Player.Pause fi prev_port=$cur_port
    done

Note:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy