本文整理汇总了Python中subprocess.Popen.flush方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.flush方法的具体用法?Python Popen.flush怎么用?Python Popen.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_clipboard
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import flush [as 别名]
def set_clipboard(text):
from subprocess import Popen, PIPE
pipe = Popen(['xsel', '--primary --input'], shell=True, stdin=PIPE).stdin
pipe.write(bytes(text, 'ascii'))
pipe.flush()
pipe.close()
示例2: __init__
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import flush [as 别名]
class AudioPlayer:
song = None
state = States.INITIAL
startup = -1
def __init__(self):
self.mplayer = None
def play(self, song=None):
if self.state == States.INITIAL or self.state == States.STOPPED:
self.song = song
index = configurations.BUFFERED_TEMP_LOCATION + "-" + self.song['artist'].replace(" ", "_") + "-" + self.song['title'].replace(" ", "_")
available = list(glob.glob(index + "*"))
if len(available) > 0:
location = available.pop(0)
else:
stream = pafy.new(song['youtube_link']).getbestaudio()
location = index+"."+stream.extension
stream.download(filepath=location)
self.mplayer = Popen(["mplayer", "-slave", "-really-quiet", location], stdin=PIPE)
self.startup = int(time.time())
self.state = States.PLAYING
elif self.state == States.PAUSED:
self.mplayer.stdin.write(b"p\n")
self.mplayer.stdin.flush()
self.state = States.PLAYING
def pause(self):
self.mplayer.write(b"p\n")
self.mplayer.flush()
self.state = States.PAUSED
def stop(self):
self.mplayer.kill()
self.state = States.STOPPED
def is_dying(self):
return time.time() > (self.song.duration-5+self.startup)
def is_stopped(self):
if self.state == States.STOPPED:
return True
elif self.state == States.INITIAL:
return False
elif self.mplayer.poll() is not None:
self.state = States.STOPPED
return self.state == States.STOPPED
def is_initial(self):
return self.state == States.INITIAL