python subprocess module, works with communicate() not with process.stdin.write() -


im creating mp3 player python in ubuntu omxplayer installed.

im using tkinter frame have play/pause button. when python script ran displays play button, once play button hit mp3 begin, , button text changes pause. user can click pause button, mp3 pauses , button text changes. cycle continues etc. using keybindings omxplayer, using subprocess module write command line.

the code have is: https://codedump.io/share/8sw4ufnig4zq/1/mp3-player

the important function musicplay:

def musicplay():     global player, playing      if musicplaybutton["text"] == "play": #if not paused         musicplaybutton["text"] = "pause"          if playing == false: #if player isn't loaded             songstring = library + "/" + librarylist[libraryindex]             player = subprocess.popen(["omxplayer","-o","local",songstring],stdin=subprocess.pipe)             playing = true          elif playing == true: #if player loaded             player.communicate(input=(bytes('q',"utf-8")))      elif musicplaybutton["text"] == "pause":         musicplaybutton["text"] = "play"         player.communicate(input=(bytes('q',"utf-8"))) 

this correctly starts mp3 , pauses mp3 first time.

reading through documentation on subprocess module, states communicate method closes stdin pipe. other questions on stack overflow, suggested replace communicate stdin.write.

when mp3 starts not pause, , seems not complete write stdin.

how can overcome problem?


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -