python - Can't give play/pause commands to any player running in background -


i trying make widget in python linux can play/pause current song, adjust volume, toggle songs,etc.

so far, able process names of music players running in background using media.role property of pulseaudio. unable give shell commands each of them because options different each player.

import subprocess sp  output = sp.check_output("pacmd list-sink-inputs", shell=true)  index = 0 while index>=0 , index<len(output):     first = output.find("role = \"music",index+1)     index = first     if index<=0:         break     index = output.rfind("properties",0,index)     test = output.find("application.name",index)     index = output.find("process.id",index)     index = output.find("\"",index)     index = index+1     index2 = output.find("\"",index)     num = output[index:index2]     print "pid="+num     proc = sp.check_output("cat \"/proc/"+num+"/comm\"", shell=true)     proc = proc[:-1]     print proc     index = output.find("media.name",index2) 

output:

pid=9895 gmusicbrowser 

maybe approaching wrong direction, objective make run player.

is there solution this?


Comments