[英]Can't write while subprocess.wait
我正在使用omxplayer編寫音樂播放器系統,一切都完成了,但是我有一個問題,我需要通過subprocess.wait()來檢測音樂何時完成,直到該過程結束為止,並且我必須向該過程寫入字節作為'p'.encode()暫停,'q'.encode()停止等...問題是我無法在等待時將字節寫入子進程...如果有人知道如何檢測進程的結尾並同時對其進行寫入,我們表示歡迎!
這是我的代碼:
class MusicPlayer(Thread):
def __init__(self, manager, playlist=[]):
self.playlist = []
self.index = 0
self.process = None
self.paused = False
self.stopped = False
self.manager = manager
self.progress_bar = MusicProgressBar(self)
self.progress_bar.start()
Thread.__init__(self)
def run(self):
while True:
if len(self.playlist) is 0:
time.sleep(1)
continue
self.process = subprocess.Popen(['omxplayer' , '-o' , 'local', self.playlist[self.index].file_url])
self.progress_bar.play(self.playlist[0].file_url)
self.paused = False
self.process.wait()
self.index += 1
if self.index >= len(self.playlist):
self.index = 0
def play(self, playlist):
self.playlist = playlist
self.index = 0
def next(self):
if self.process is None: return
self.process.stdin.write('q'.encode())
self.process.stdin.flush()
def before(self):
for i in range(0,2):
self.index -= 1
if self.index < 0:
self.index = len(self.playlist-1)
def stop(self):
if self.process is None: return
self.process.stdin.write('q'.encode())
self.process.stdin.flush()
self.stopped = True
def pause(self):
if self.process is None: return
if self.paused: return
self.process.stdin.write('p'.encode())
self.process.stdin.flush()
self.paused = True
def resume(self):
if self.process is None: return
if not self.paused: return
self.process.stdin.write('p'.encode())
self.process.stdin.flush()
self.paused = False
非常感謝您的回答! 最好的問候,朱利安
我想你可以改變這條線
self.process.wait()
到一會兒循環
while self.process.poll() not None:
c = stdscr.getch()
if c != -1:
# check p, q
那就是繼續輪詢omxplayer進程是否完成。 如果沒有,請檢查是否有按鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.